Skip to content

Commit 394fd3a

Browse files
committed
Merge code changes from upstream 8.13.53
1 parent 8b91cb7 commit 394fd3a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

python/phonenumbers/phonenumberutil.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,10 +1686,13 @@ def format_out_of_country_keeping_alpha_chars(numobj, region_calling_from):
16861686
region_code = region_code_for_country_code(country_code)
16871687
# Metadata cannot be None because the country calling code is valid.
16881688
metadata_for_region = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_code)
1689+
# Strip any extension
1690+
extension, stripped_number = _maybe_strip_extension(num_raw_input)
1691+
# Append the formatted extension
16891692
formatted_number = _maybe_append_formatted_extension(numobj,
16901693
metadata_for_region,
16911694
PhoneNumberFormat.INTERNATIONAL,
1692-
num_raw_input)
1695+
stripped_number)
16931696
if i18n_prefix_for_formatting:
16941697
formatted_number = (i18n_prefix_for_formatting + U_SPACE +
16951698
unicod(country_code) + U_SPACE + formatted_number)
@@ -2449,6 +2452,7 @@ def _test_number_length(national_number, metadata, numtype=PhoneNumberType.UNKNO
24492452

24502453

24512454
def is_possible_number_with_reason(numobj):
2455+
"""See documentation for is_possible_number_for_type_with_reason"""
24522456
return is_possible_number_for_type_with_reason(numobj, PhoneNumberType.UNKNOWN)
24532457

24542458

@@ -2477,6 +2481,14 @@ def is_possible_number_for_type_with_reason(numobj, numtype):
24772481
area codes for fixed line numbers), it will return false for the
24782482
subscriber-number-only version.
24792483
2484+
There is a known <a
2485+
href="https://issuetracker.google.com/issues/335892662">issue</a> with this
2486+
method: if a number is possible only in a certain region among several
2487+
regions that share the same country calling code, this method will consider
2488+
only the "main" region. For example, +1310xxxx are valid numbers in
2489+
Canada. However, they are not possible in the US. As a result, this method
2490+
will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
2491+
24802492
Arguments:
24812493
numobj -- The number object that needs to be checked
24822494
numtype -- The type we are interested in

python/tests/phonenumberutiltest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ def testFormatOutOfCountryKeepingAlphaChars(self):
620620
self.assertEqual("1 800 SIX-FLAG",
621621
phonenumbers.format_out_of_country_keeping_alpha_chars(alphaNumericNumber, "BS"))
622622

623+
# Testing a number with extension.
624+
alphaNumericNumberWithExtn = phonenumbers.parse("800 SIX-flag ext. 1234", "US", keep_raw_input=True)
625+
self.assertEqual("0011 1 800 SIX-FLAG extn. 1234",
626+
phonenumbers.format_out_of_country_keeping_alpha_chars(alphaNumericNumberWithExtn, "AU"))
627+
623628
# Testing that if the raw input doesn't exist, it is formatted using
624629
# formatOutOfCountryCallingNumber.
625630
alphaNumericNumber.raw_input = None

0 commit comments

Comments
 (0)