Skip to content

Commit 36d92e7

Browse files
committed
Merge code changes from upstream r702
1 parent 2c891ab commit 36d92e7

2 files changed

Lines changed: 2 additions & 36 deletions

File tree

python/phonenumbers/phonenumberutil.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,9 +1635,7 @@ def number_type(numobj):
16351635

16361636
def _number_type_helper(national_number, metadata):
16371637
"""Return the type of the given number against the metadata"""
1638-
general_desc = metadata.general_desc
1639-
if (general_desc.national_number_pattern is None or
1640-
not _is_number_matching_desc(national_number, general_desc)):
1638+
if not _is_number_matching_desc(national_number, metadata.general_desc):
16411639
return PhoneNumberType.UNKNOWN
16421640
if _is_number_matching_desc(national_number, metadata.premium_rate):
16431641
return PhoneNumberType.PREMIUM_RATE
@@ -1734,16 +1732,7 @@ def is_valid_number_for_region(numobj, region_code):
17341732
# Either the region code was invalid, or the country calling code for
17351733
# this number does not match that of the region code.
17361734
return False
1737-
general_desc = metadata.general_desc
17381735
nsn = national_significant_number(numobj)
1739-
1740-
# For regions where we don't have metadata for PhoneNumberDesc, we treat
1741-
# any number passed in as a valid number if its national significant
1742-
# number is between the minimum and maximum lengths defined by ITU for a
1743-
# national significant number.
1744-
if general_desc.national_number_pattern is None:
1745-
num_len = len(nsn)
1746-
return (num_len > _MIN_LENGTH_FOR_NSN and num_len < _MAX_LENGTH_FOR_NSN)
17471736
return (_number_type_helper(nsn, metadata) != PhoneNumberType.UNKNOWN)
17481737

17491738

@@ -2012,16 +2001,6 @@ def is_possible_number_with_reason(numobj):
20122001
# Metadata cannot be None because the country calling code is valid.
20132002
metadata = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_code)
20142003
general_desc = metadata.general_desc
2015-
2016-
# Handling case of numbers with no metadata.
2017-
if general_desc.national_number_pattern is None:
2018-
num_len = len(national_number)
2019-
if num_len < _MIN_LENGTH_FOR_NSN:
2020-
return ValidationResult.TOO_SHORT
2021-
elif num_len > _MAX_LENGTH_FOR_NSN:
2022-
return ValidationResult.TOO_LONG
2023-
else:
2024-
return ValidationResult.IS_POSSIBLE
20252004
possible_re = re.compile(general_desc.possible_number_pattern or U_EMPTY_STRING)
20262005
return _test_number_length_against_pattern(possible_re, national_number)
20272006

python/tests/phonenumberutiltest.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,19 +1235,6 @@ def testIsPossibleNumberWithReason(self):
12351235
self.assertEqual(ValidationResult.TOO_LONG,
12361236
phonenumbers.is_possible_number_with_reason(INTERNATIONAL_TOLL_FREE_TOO_LONG))
12371237

1238-
# Try with number that we don't have metadata for.
1239-
adNumber = PhoneNumber(country_code=376, national_number=12345)
1240-
self.assertEqual(ValidationResult.IS_POSSIBLE,
1241-
phonenumbers.is_possible_number_with_reason(adNumber))
1242-
adNumber.country_code = 376
1243-
adNumber.national_number = to_long(1)
1244-
self.assertEqual(ValidationResult.TOO_SHORT,
1245-
phonenumbers.is_possible_number_with_reason(adNumber))
1246-
adNumber.country_code = 376
1247-
adNumber.national_number = to_long(123456789012345678)
1248-
self.assertEqual(ValidationResult.TOO_LONG,
1249-
phonenumbers.is_possible_number_with_reason(adNumber))
1250-
12511238
def testIsNotPossibleNumber(self):
12521239
self.assertFalse(phonenumbers.is_possible_number(US_LONG_NUMBER))
12531240
self.assertFalse(phonenumbers.is_possible_number(INTERNATIONAL_TOLL_FREE_TOO_LONG))
@@ -2238,7 +2225,7 @@ def testCountryWithNoNumberDesc(self):
22382225
self.assertEqual("+37612345", phonenumbers.format_number(adNumber, PhoneNumberFormat.E164))
22392226
self.assertEqual("12345", phonenumbers.format_number(adNumber, PhoneNumberFormat.NATIONAL))
22402227
self.assertEqual(PhoneNumberType.UNKNOWN, phonenumbers.number_type(adNumber))
2241-
self.assertTrue(phonenumbers.is_valid_number(adNumber))
2228+
self.assertFalse(phonenumbers.is_valid_number(adNumber))
22422229

22432230
# Test dialing a US number from within Andorra.
22442231
self.assertEqual("00 1 650 253 0000",

0 commit comments

Comments
 (0)