Python: module phonenumbers.shortnumberinfo

phonenumbers.shortnumberinfo | index phonenumbers/shortnumberinfo.py

`Methods for getting information about short phone numbers,
such as short codes and emergency numbers.
Note most commercial short numbers are not handled here, but by phonenumberutil.py`

Classes
`` |  | builtins.object ShortNumberCost
class ShortNumberCost(builtins.object)
`` | `Cost categories of short numbers.`
| Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes defined here: PREMIUM_RATE = 2 STANDARD_RATE = 1 TOLL_FREE = 0 UNKNOWN_COST = 3

Functions
`` |  | connects_to_emergency_number(number, region_code) `Returns whether the given number, exactly as dialled, might be used to connect to an emergency service in the given region. This function accepts a string, rather than a PhoneNumber, because it needs to distinguish cases such as "+1 911" and "911", where the former may not connect to an emergency service in all cases but the latter would. This function takes into account cases where the number might contain formatting, or might have additional digits appended (when it is okay to do that in the specified region). Arguments: number -- The phone number to test. region_code -- The region where the phone number is being dialed. Returns whether the number might be used to connect to an emergency service in the given region.` expected_cost(numobj) `Gets the expected cost category of a short number (however, nothing is implied about its validity). If the country calling code is unique to a region, this method behaves exactly the same as expected_cost_for_region. However, if the country calling code is shared by multiple regions, then it returns the highest cost in the sequence PREMIUM_RATE, UNKNOWN_COST, STANDARD_RATE, TOLL_FREE. The reason for the position of UNKNOWN_COST in this order is that if a number is UNKNOWN_COST in one region but STANDARD_RATE or TOLL_FREE in another, its expected cost cannot be estimated as one of the latter since it might be a PREMIUM_RATE number. For example, if a number is STANDARD_RATE in the US, but TOLL_FREE in Canada, the expected cost returned by this method will be STANDARD_RATE, since the NANPA countries share the same country calling code. Note: If the region from which the number is dialed is known, it is highly preferable to call expected_cost_for_region instead. Arguments: numobj -- the short number for which we want to know the expected cost category Return the highest expected cost category of the short number in the region(s) with the given country calling code` expected_cost_for_region(short_numobj, region_dialing_from) `Gets the expected cost category of a short number when dialled from a region (however, nothing is implied about its validity). If it is important that the number is valid, then its validity must first be checked using is_valid_short_number_for_region. Note that emergency numbers are always considered toll-free. Example usage: short_number = "110" region_code = "FR" if phonenumbers.is_valid_short_number_for_region(short_number, region_code): cost = phonenumbers.expected_cost(short_number, region_code) # ShortNumberCost # Do something with the cost information here. Arguments: short_numobj -- the short number for which we want to know the expected cost category as a PhoneNumber object. region_dialing_from -- the region from which the number is dialed Return the expected cost category for that region of the short number. Returns UNKNOWN_COST if the number does not match a cost category. Note that an invalid number may match any cost category.` is_carrier_specific(numobj) `Given a valid short number, determines whether it is carrier-specific (however, nothing is implied about its validity). Carrier-specific numbers may connect to a different end-point, or not connect at all, depending on the user's carrier. If it is important that the number is valid, then its validity must first be checked using is_valid_short_number or is_valid_short_number_for_region. Arguments: numobj -- the valid short number to check Returns whether the short number is carrier-specific, assuming the input was a valid short number.` is_carrier_specific_for_region(numobj, region_dialing_from) `Given a valid short number, determines whether it is carrier-specific when dialed from the given region (however, nothing is implied about its validity). Carrier-specific numbers may connect to a different end-point, or not connect at all, depending on the user's carrier. If it is important that the number is valid, then its validity must first be checked using isValidShortNumber or isValidShortNumberForRegion. Returns false if the number doesn't match the region provided. Arguments: numobj -- the valid short number to check region_dialing_from -- the region from which the number is dialed Returns whether the short number is carrier-specific, assuming the input was a valid short number.` is_emergency_number(number, region_code) `Returns true if the given number exactly matches an emergency service number in the given region. This method takes into account cases where the number might contain formatting, but doesn't allow additional digits to be appended. Note that is_emergency_number(number, region) implies connects_to_emergency_number(number, region). Arguments: number -- The phone number to test. region_code -- The region where the phone number is being dialed. Returns if the number exactly matches an emergency services number in the given region.` is_possible_short_number(numobj) `Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns True if it's possible in any of them. This provides a more lenient check than is_valid_short_number. Arguments: numobj -- the short number to check Return whether the number is a possible short number.` is_possible_short_number_for_region(short_numobj, region_dialing_from) `Check whether a short number is a possible number when dialled from a region. This provides a more lenient check than is_valid_short_number_for_region. Arguments: short_numobj -- the short number to check as a PhoneNumber object. region_dialing_from -- the region from which the number is dialed Return whether the number is a possible short number.` is_sms_service_for_region(numobj, region_dialing_from) `Given a valid short number, determines whether it is an SMS service (however, nothing is implied about its validity). An SMS service is where the primary or only intended usage is to receive and/or send text messages (SMSs). This includes MMS as MMS numbers downgrade to SMS if the other party isn't MMS-capable. If it is important that the number is valid, then its validity must first be checked using is_valid_short_number or is_valid_short_number_for_region. Returns False if the number doesn't match the region provided. Arguments: numobj -- the valid short number to check region_dialing_from -- the region from which the number is dialed Returns whether the short number is an SMS service in the provided region, assuming the input was a valid short number.` is_valid_short_number(numobj) `Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns True if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. See is_valid_short_number_for_region for details. Arguments: numobj - the short number for which we want to test the validity Return whether the short number matches a valid pattern` is_valid_short_number_for_region(short_numobj, region_dialing_from) `Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. Arguments: short_numobj -- the short number to check as a PhoneNumber object. region_dialing_from -- the region from which the number is dialed Return whether the short number matches a valid pattern`

Data
`` |  | SUPPORTED_SHORT_REGIONS = ['AC', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', ...] U_EMPTY_STRING = ''