EBookContacts.PhoneNumber

Fields

None

Methods

class

compare_strings (first_number, second_number)

class

compare_strings_with_region (first_number, second_number, region_code)

class

error_quark ()

class

from_string (phone_number, region_code)

class

get_country_code_for_region (region_code)

class

get_default_region ()

class

is_supported ()

compare (second_number)

copy ()

free ()

get_country_code (source)

get_national_number ()

to_string (format)

Details

class EBookContacts.PhoneNumber

This opaque type describes a parsed phone number. It can be copied using EBookContacts.PhoneNumber.copy(). To release it call EBookContacts.PhoneNumber.free().

New in version 3.8.

classmethod compare_strings(first_number, second_number)
Parameters:
Raises:

GLib.Error

Returns:

The quality of matching for the two phone numbers.

Return type:

EBookContacts.PhoneNumberMatch

Compares two phone numbers.

New in version 3.8.

classmethod compare_strings_with_region(first_number, second_number, region_code)
Parameters:
Raises:

GLib.Error

Returns:

The quality of matching for the two phone numbers.

Return type:

EBookContacts.PhoneNumberMatch

Compares two phone numbers within the context of region_code.

New in version 3.8.

classmethod error_quark()
Return type:

int

classmethod from_string(phone_number, region_code)
Parameters:
  • phone_number (str) – the phone number to parse

  • region_code (str or None) – a two-letter country code, or None

Raises:

GLib.Error

Returns:

a new EBookContacts.PhoneNumber instance on success, or None on error. Call EBookContacts.PhoneNumber.free() to release this instance.

Return type:

EBookContacts.PhoneNumber

Parses the string passed in phone_number. Note that no validation is performed whether the recognized phone number is valid for a particular region.

The two-letter country code passed in region_code only is used if the phone_number is not written in international format. The application’s default region as returned by EBookContacts.PhoneNumber.get_default_region() is used if region_code is None.

If the number is guaranteed to start with a ‘+’ followed by the country calling code, then “ZZ” can be passed for region_code.

New in version 3.8.

classmethod get_country_code_for_region(region_code)
Parameters:

region_code (str or None) – a two-letter country code, a locale name, or None

Raises:

GLib.Error

Returns:

a valid country calling code, or zero if an unknown region code was passed.

Return type:

int

Retrieves the preferred country calling code for region_code, e.g. 358 for “fi” or 1 for “en_USUTF-8”.

If None is passed for region_code the default region as returned by EBookContacts.PhoneNumber.get_default_region() is used.

New in version 3.8.

classmethod get_default_region()
Raises:

GLib.Error

Returns:

a newly allocated string containing the current locale’s two-letter code for phone number parsing.

Return type:

str

Retrieves the current two-letter country code that’s used by default for parsing phone numbers in EBookContacts.PhoneNumber.from_string(). It can be useful to store this number before parsing a bigger number of phone numbers.

The result of this functions depends on the current setup of the %LC_ADDRESS category: If that category provides a reasonable value for %_NL_ADDRESS_COUNTRY_AB2 this value is returned. Otherwise the locale name configured for %LC_ADDRESS is parsed.

New in version 3.8.

classmethod is_supported()
Returns:

True if phone number support is available.

Return type:

bool

Checks if phone number support is available. It is recommended to call this function before using any of the phone-utils functions to ensure that the required functionality is available, and to pick alternative mechanisms if needed.

New in version 3.8.

compare(second_number)
Parameters:

second_number (EBookContacts.PhoneNumber) – the second EBookContacts.PhoneNumber to compare

Returns:

The quality of matching for the two phone numbers.

Return type:

EBookContacts.PhoneNumberMatch

Compares two phone numbers.

New in version 3.8.

copy()
Returns:

A newly allocated EBookContacts.PhoneNumber instance. Call EBookContacts.PhoneNumber.free() to release this instance.

Return type:

EBookContacts.PhoneNumber

Makes a copy of self.

New in version 3.8.

free()

Released the memory occupied by self.

New in version 3.8.

get_country_code(source)
Parameters:

source (EBookContacts.PhoneNumberCountrySource or None) – an optional location for storing the phone number’s origin, or None

Returns:

A valid country calling code, or zero if no code is known.

Return type:

int

Queries the self's country calling code and optionally stores the country calling code’s origin in source. For instance when parsing “+1-617-5423789” this function would return one and assing EBookContacts.PhoneNumberCountrySource.FQTN to source.

New in version 3.8.

get_national_number()
Returns:

The national portion of self.

Return type:

str

Queries the national portion of self without any call-out prefixes. For instance when parsing “+1-617-5423789” this function would return the string “6175423789”.

New in version 3.8.

to_string(format)
Parameters:

format (EBookContacts.PhoneNumberFormat) – the phone number format to apply

Returns:

A formatted string for self.

Return type:

str

Describes the self according to the rules applying to format.

New in version 3.8.