Example #1
0
 def to_python(self, value):
     if isinstance(value, basestring) and value != '':
         try:
             value = format_number(parse(value,"US"),PhoneNumberFormat.INTERNATIONAL)
         except NumberParseException:
             pass
     return value
Example #2
0
 def testGBLocalNumberLength(self):
     # Python version extra test.  Issue #172.
     numobj = phonenumberutil.parse("+4408001111", "GB")
     self.assertEqual(
         "+44 800 1111",
         phonenumberutil.format_number(
             numobj, phonenumberutil.PhoneNumberFormat.INTERNATIONAL))
Example #3
0
def prefix_description_for_number(data, longest_prefix, numobj, lang, script=None, region=None):
    name_list = []

    e164_num = phonenumberutil.format_number(numobj, phonenumberutil.PhoneNumberFormat.E164)
    if not e164_num.startswith(U_PLUS):  # pragma no cover
        # Can only hit this arm if there's an internal error in the rest of
        # the library
        raise Exception("Expect E164 number to start with +")

    for prefix_len in range(5, 3, -1):
        p = e164_num[1:(1 + prefix_len)]
        if p in data:
            # This prefix is present in the geocoding data, as a dictionary
            # mapping language info to location name.
            name = prefix._find_lang(data[p], lang, script, region)
            if name is not None:
                # return name
                name_list.append(name)
            # else:
                # return U_EMPTY_STRING
                # name_list.append(U_EMPTY_STRING)
    # return U_EMPTY_STRING
    # name_list.append(U_EMPTY_STRING)
    return name_list
Example #4
0
        logging.debug('Parsing config files...')
        config = ConfigParser.RawConfigParser()
        config.read(args['--config'])
        api_key = config.get('Password', 'api_key')
        api_secret = config.get('Password', 'api_secret')
    except Exception, e:
        logging.error(traceback.format_exc())
        exit(e)

    msg = args['MESSAGE']
    f_num = args['FROM_NUM']
    t_num = args['TO_NUM']
    country = args['--country']
    if t_num[0] == '+':
        logging.debug('Senderid use E164 form, e.g. +886123456...')
        from_num = phonenumberutil.format_number(phonenumberutil.parse(f_num, country) \
                , phonenumberutil.PhoneNumberFormat.E164).lstrip('+')
    logging.debug('Senderid use national form, e.g. 09123456...')
    from_num = ''.join(phonenumberutil.format_number(phonenumberutil.parse(f_num, country) \
             , phonenumberutil.PhoneNumberFormat.NATIONAL).split())
    to_num = phonenumberutil.format_number(phonenumberutil.parse(t_num, country) \
            , phonenumberutil.PhoneNumberFormat.E164)

    sms = NexmoMessage({
            'reqtype': 'json',
            'type': 'unicode',
            'api_secret': api_secret,
            'api_key': api_key,
            'from': from_num,
            'to': to_num,
            'text': msg
          })
Example #5
0
def format_us_phone_number(value):
    phone = parse(value, 'US')
    formatted = format_number(phone, PhoneNumberFormat.E164)
    if phone.extension:
        formatted += 'x%s' % phone.extension
    return formatted
Example #6
0
def format_us_phone_number(value):
    phone = parse(value, 'US')
    formatted = format_number(phone, PhoneNumberFormat.E164)
    if phone.extension:
        formatted += 'x%s' % phone.extension
    return formatted
Example #7
0
 def value_to_string(self, obj):
     value = self._get_val_from_obj(obj)
     try:
         return format_number(parse(value,"US"),PhoneNumberFormat.INTERNATIONAL)
     except NumberParseException:
         return value