Beispiel #1
0
 def testGetDescriptionForMobilePortableRegion(self):
     self.assertEqual("British carrier",
                      name_for_number(UK_MOBILE1, _ENGLISH))
     self.assertEqual(u"Brittisk operat\u00F6r",
                      name_for_number(UK_MOBILE1, "sv", region="SE"))
     self.assertEqual("British carrier",
                      name_for_number(UK_MOBILE1, _FRENCH))
     # Returns an empty string because the UK implements mobile number portability.
     self.assertEqual("", safe_display_name(UK_MOBILE1, _ENGLISH))
Beispiel #2
0
def _parse_single_number_single_locale(phone_number, locale, language=DEFAULT_LANGUAGE):
    '''
    Tries to parse number. 

    Raises:
        NumberParseException if the string is not a potentially viable number
        ValueError if the string was for a potentially viable number that is not valid
    '''
    number = phonenumbers.parse(phone_number, locale)

    if not phonenumbers.is_valid_number(number):
        raise ValueError("not a valid number")

    number_details = {}
    number_details['raw_input'] = phone_number
    number_details['E164'] = phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.E164)
    number_details['assumed_local_locale'] = locale
    number_details['region'] = phonenumbers.region_code_for_number(number)
    number_details['country'] = geocoder.country_name_for_number(number, language)
    number_details['description'] = geocoder.description_for_number(number, language)
    number_details['carrier'] = carrier.safe_display_name(number, language)
    number_details['comment'] = ""

    return number_details
Beispiel #3
0
 def testGetDescriptionForNonMobilePortableRegion(self):
     self.assertEqual("Angolan carrier", name_for_number(AO_MOBILE1, _ENGLISH))
     self.assertEqual("Angolan carrier", safe_display_name(AO_MOBILE1, _ENGLISH))
 def testGetDescriptionForMobilePortableRegion(self):
     self.assertEqual("British carrier", name_for_number(UK_MOBILE1, _ENGLISH))
     self.assertEqual(u("Brittisk operat\u00F6r"), name_for_number(UK_MOBILE1, "sv", region="SE"))
     self.assertEqual("British carrier", name_for_number(UK_MOBILE1, _FRENCH))
     # Returns an empty string because the UK implements mobile number portability.
     self.assertEqual("", safe_display_name(UK_MOBILE1, _ENGLISH))