Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions python/dialpad_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import phonenumbers

# Fixed by Phonenumbers Cases
valid_strings = ['+442083661177',
'+658003211137',
'+20573925008',
'+2057392500',
'+20225777444',
'+84384813220',
'+84357659677',
'+56232512653', # https://switchcomm.atlassian.net/browse/TEL-9285
'+525547808256',
'+13677395285',
'+16892226575',
'+18404440531',
'+48477314848',
'+6569786318',
'+6560115374', # https://switchcomm.atlassian.net/browse/TEL-14616
'+576015088865', # https://switchcomm.atlassian.net/browse/TEL-14616
'+16562013774', # https://dialpad.atlassian.net/browse/DP-60739
'+18352010583', # https://dialpad.atlassian.net/browse/DP-67544
'+15572003655', # https://dialpad.atlassian.net/browse/DP-67544
'+61493772332', # https://dialpad.atlassian.net/browse/DP-73324
'+13292010961', # https://dialpad.atlassian.net/browse/TEL-21003
'+17282011957', # https://dialpad.atlassian.net/browse/TEL-21287
'+17302559291', # https://dialpad.atlassian.net/browse/TEL-23411
]

print ('######### - VALID BY LIBRARY - ################')
for l in valid_strings:
x = phonenumbers.parse(l, None)
print ('%15s' % l, '%10s' % phonenumbers.is_valid_number(x), '%25s' % x)

# To be fixed by Dialpad Changes
dialpad_cases = ['+6278033212174', # https://switchcomm.atlassian.net/browse/DP-13742
'+63283168971', # Philipines
'+8031000000141', # Dialpadistan
'+2250757715034', # Ivory Coast - New Format
'+2252721214601', # Ivory Coast - New Format,
'+2342012278701', # Nigeria, new format https://dialpad.atlassian.net/browse/TEL-21006
'+23412278701', # Nigeria, old format for backwards comp
]

print ('######### - VALID BY DIALPAD - ################')
for l in dialpad_cases:
try:
x = phonenumbers.parse(l, None)
print ('%15s' % l, '%10s' % phonenumbers.is_valid_number(x), '%25s' % x)
except Exception as e:
print ('%15s' % l, '%25s' % e)

# Invalid Strings
invalid_strings = ['+4916190899790', # https://switchcomm.atlassian.net/browse/TEL-8824 Not Fixed
'+2022577744',
'+205739250',
]

print ('######### - INVALID NUMBERS - ################')
for l in invalid_strings:
x = phonenumbers.parse(l, None)
print ('%15s' % l, '%10s' % phonenumbers.is_valid_number(x), '%25s' % x)

# National Format match
national_format_match = {'+525547808256': '55 4780 8256'}

print ('######### - NUMBER FORMAT VALIDITY - ################')
for l in national_format_match:
x = phonenumbers.parse(l, None)
y = phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL)
if national_format_match[l] == y:
status = 'Success'
else:
status = 'Failed'
print (l), '-> %10s : %s' % (y, status)

# Number validity check
number_validity_check = {'1932621160': 'BR'}
print ('######### - REGION NUMBER VALIDITY - ###############')
for l in number_validity_check:
region = number_validity_check[l]
x = phonenumbers.parse(l, region)
print ('%15s' % l, '%10s -> Region : %5s' % (phonenumbers.is_valid_number(x), region))

5 changes: 5 additions & 0 deletions python/phonenumbers/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

_AVAILABLE_REGION_CODES = ['AC','AD','AE','AF','AG','AI','AL','AM','AO','AR','AS','AT','AU','AW','AX','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BL','BM','BN','BO','BQ','BR','BS','BT','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CW','CX','CY','CZ','DE','DJ','DK','DM','DO','DZ','EC','EE','EG','EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','GA','GB','GD','GE','GF','GG','GH','GI','GL','GM','GN','GP','GQ','GR','GT','GU','GW','GY','HK','HN','HR','HT','HU','ID','IE','IL','IM','IN','IO','IQ','IR','IS','IT','JE','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR','KW','KY','KZ','LA','LB','LC','LI','LK','LR','LS','LT','LU','LV','LY','MA','MC','MD','ME','MF','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PR','PS','PT','PW','PY','QA','RE','RO','RS','RU','RW','SA','SB','SC','SD','SE','SG','SH','SI','SJ','SK','SL','SM','SN','SO','SR','SS','ST','SV','SX','SY','SZ','TA','TC','TD','TG','TH','TJ','TK','TL','TM','TN','TO','TR','TT','TV','TW','TZ','UA','UG','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','XK','YE','YT','ZA','ZM','ZW']
_AVAILABLE_NONGEO_COUNTRY_CODES = [800, 808, 870, 878, 881, 882, 883, 888, 979]
_DIALPADISTAN_NONGEO_REGION_CODES = ['DP']

def _load_region(code):
__import__("region_%s" % code, globals(), locals(),
Expand All @@ -29,6 +30,9 @@ def _load_region(code):
for _country_code in _AVAILABLE_NONGEO_COUNTRY_CODES:
PhoneMetadata.register_nongeo_region_loader(_country_code, _load_region)

for region_code in _DIALPADISTAN_NONGEO_REGION_CODES:
PhoneMetadata.register_region_loader(region_code, _load_region)

from .alt_format_255 import PHONE_ALT_FORMAT_255
from .alt_format_27 import PHONE_ALT_FORMAT_27
from .alt_format_30 import PHONE_ALT_FORMAT_30
Expand Down Expand Up @@ -298,4 +302,5 @@ def _load_region(code):
995: ("GE",),
996: ("KG",),
998: ("UZ",),
803: ("DP",), # Dialpadistan
}
8 changes: 8 additions & 0 deletions python/phonenumbers/data/region_DP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Auto-generated file, do not edit by hand. 800 metadata"""
from ..phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata

PHONE_METADATA_DP = PhoneMetadata(id='DP', country_code=803, international_prefix=None,
general_desc=PhoneNumberDesc(national_number_pattern='\\d{10}', example_number='1000000141', possible_length=(10,)),
voip=PhoneNumberDesc(national_number_pattern='\\d{10}', example_number='1000000141', possible_length=(10,)),
number_format=[NumberFormat(pattern='(\\d{3})(\\d{7})', format='\\1\\2')],
leading_zero_possible=False)
2 changes: 1 addition & 1 deletion python/phonenumbers/data/region_ID.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
general_desc=PhoneNumberDesc(national_number_pattern='00[1-9]\\d{9,14}|(?:[1-36]|8\\d{5})\\d{6}|00\\d{9}|[1-9]\\d{8,10}|[2-9]\\d{7}', possible_length=(7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), possible_length_local_only=(5, 6)),
fixed_line=PhoneNumberDesc(national_number_pattern='2[124]\\d{7,8}|619\\d{8}|2(?:1(?:14|500)|2\\d{3})\\d{3}|61\\d{5,8}|(?:2(?:[35][1-4]|6[0-8]|7[1-6]|8\\d|9[1-8])|3(?:1|[25][1-8]|3[1-68]|4[1-3]|6[1-3568]|7[0-469]|8\\d)|4(?:0[1-589]|1[01347-9]|2[0-36-8]|3[0-24-68]|43|5[1-378]|6[1-5]|7[134]|8[1245])|5(?:1[1-35-9]|2[25-8]|3[124-9]|4[1-3589]|5[1-46]|6[1-8])|6(?:[25]\\d|3[1-69]|4[1-6])|7(?:02|[125][1-9]|[36]\\d|4[1-8]|7[0-36-9])|9(?:0[12]|1[013-8]|2[0-479]|5[125-8]|6[23679]|7[159]|8[01346]))\\d{5,8}', example_number='218350123', possible_length=(7, 8, 9, 10, 11), possible_length_local_only=(5, 6)),
mobile=PhoneNumberDesc(national_number_pattern='8[1-35-9]\\d{7,10}', example_number='812345678', possible_length=(9, 10, 11, 12)),
toll_free=PhoneNumberDesc(national_number_pattern='00(?:1803\\d{5,11}|7803\\d{7})|(?:177\\d|800)\\d{5,7}', example_number='8001234567', possible_length=(8, 9, 10, 11, 12, 13, 14, 15, 16, 17)),
toll_free=PhoneNumberDesc(national_number_pattern='00[17]803\\d{7}|(?:177\\d|800)\\d{5,7}|001803\\d{6}|7803\\d{7}', example_number='8001234567', possible_length=(8, 9, 10, 11, 12, 13)),
premium_rate=PhoneNumberDesc(national_number_pattern='809\\d{7}', example_number='8091234567', possible_length=(10,)),
shared_cost=PhoneNumberDesc(national_number_pattern='804\\d{7}', example_number='8041234567', possible_length=(10,)),
uan=PhoneNumberDesc(national_number_pattern='(?:1500|8071\\d{3})\\d{3}', example_number='8071123456', possible_length=(7, 10)),
Expand Down
6 changes: 3 additions & 3 deletions python/phonenumbers/data/region_NG.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from ..phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata

PHONE_METADATA_NG = PhoneMetadata(id='NG', country_code=234, international_prefix='009',
general_desc=PhoneNumberDesc(national_number_pattern='38\\d{6}|[78]\\d{9,13}|(?:20|9\\d)\\d{8}', possible_length=(8, 10, 11, 12, 13, 14), possible_length_local_only=(6, 7)),
fixed_line=PhoneNumberDesc(national_number_pattern='(?:20(?:[1259]\\d|3[013-9]|4[1-8]|6[024-689]|7[1-79]|8[2-9])|38)\\d{6}', example_number='2033123456', possible_length=(8, 10), possible_length_local_only=(6, 7)),
mobile=PhoneNumberDesc(national_number_pattern='(?:702[0-24-9]|819[01])\\d{6}|(?:7(?:0[13-9]|[12]\\d)|8(?:0[1-9]|1[0-8])|9(?:0[1-9]|1[1-6]))\\d{7}', example_number='8021234567', possible_length=(10,)),
general_desc=PhoneNumberDesc(national_number_pattern='(?:20)?((?:[124-7]|9\\d{3})\\d{6}|[1-9]\\d{7}|[78]\\d{9,13})|(?:[124-7]|9\\d{3})\\d{6}|[1-9]\\d{7}|[78]\\d{9,13}', possible_length=(7, 8, 10, 11, 12, 13, 14), possible_length_local_only=(5, 6, 8)),
fixed_line=PhoneNumberDesc(national_number_pattern='(?:20)?((?:(?:[1-356]\\d|4[02-8]|8[2-9])\\d|9(?:0[3-9]|[1-9]\\d))\\d{5}|7(?:0(?:[013-689]\\d|2[0-24-9])\\d{3,4}|[1-79]\\d{6})|(?:[12]\\d|4[147]|5[14579]|6[1578]|7[1-3578])\\d{5})|(?:(?:[1-356]\\d|4[02-8]|8[2-9])\\d|9(?:0[3-9]|[1-9]\\d))\\d{5}|7(?:0(?:[013-689]\\d|2[0-24-9])\\d{3,4}|[1-79]\\d{6})|(?:[12]\\d|4[147]|5[14579]|6[1578]|7[1-3578])\\d{5}', example_number='18040123', possible_length=(7, 8, 10), possible_length_local_only=(5, 6, 8)),
mobile=PhoneNumberDesc(national_number_pattern='(?:702[0-24-9]|819[01])\\d{6}|(?:70[13-689]|8(?:0[1-9]|1[0-8])|9(?:0[1-9]|1[1-356]))\\d{7}', example_number='8021234567', possible_length=(10,)),
toll_free=PhoneNumberDesc(national_number_pattern='800\\d{7,11}', example_number='80017591759', possible_length=(10, 11, 12, 13, 14)),
uan=PhoneNumberDesc(national_number_pattern='700\\d{7,11}', example_number='7001234567', possible_length=(10, 11, 12, 13, 14)),
national_prefix='0',
Expand Down
Loading