Skip to content

Commit cc106cf

Browse files
committed
Fix up some python3 purity issues
1 parent 67fb5ab commit cc106cf

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

python/phonenumbers/carrier.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# See the License for the specific language governing permissions and
2626
# limitations under the License.
2727

28+
from .util import prnt, u, U_EMPTY_STRING
2829
from .phonenumberutil import PhoneNumberType, number_type
2930
from .phonenumberutil import region_code_for_number
3031
from .phonenumberutil import is_mobile_number_portable_region
@@ -39,7 +40,7 @@
3940
import sys
4041
if (os.path.basename(sys.argv[0]) == "buildmetadatafromxml.py" or
4142
os.path.basename(sys.argv[0]) == "buildprefixdata.py"):
42-
print >> sys.stderr, "Failed to import generated data (but OK as during autogeneration)"
43+
prnt("Failed to import generated data (but OK as during autogeneration)", file=sys.stderr)
4344
CARRIER_DATA = {'1': {'en': u('United States')}}
4445
CARRIER_LONGEST_PREFIX = 1
4546
else:
@@ -101,7 +102,7 @@ def name_for_number(numobj, lang, script=None, region=None):
101102
ntype = number_type(numobj)
102103
if _is_mobile(ntype):
103104
return name_for_valid_number(numobj, lang, script, region)
104-
return ""
105+
return U_EMPTY_STRING
105106

106107

107108
def safe_display_name(numobj, lang, script=None, region=None):
@@ -125,7 +126,7 @@ def safe_display_name(numobj, lang, script=None, region=None):
125126
Returns a carrier name that is safe to display to users, or the empty string.
126127
"""
127128
if is_mobile_number_portable_region(region_code_for_number(numobj)):
128-
return ""
129+
return U_EMPTY_STRING
129130
return name_for_number(numobj, lang, script, region)
130131

131132

python/phonenumbers/phonenumbermatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _get_national_number_groups(numobj, formatting_pattern=None):
319319
end_index = rfc3966_format.find(U_SEMICOLON)
320320
if end_index < 0:
321321
end_index = len(rfc3966_format)
322-
322+
323323
# The country-code will have a '-' following it.
324324
start_index = rfc3966_format.find(U_DASH) + 1
325325
return rfc3966_format[start_index:end_index].split(U_DASH)

python/phonenumbers/prefix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Utilities for handling prefix dictionaries"""
22

3-
from .util import U_EMPTY_STRING
3+
from .util import U_EMPTY_STRING, U_PLUS
44
from .phonenumberutil import format_number, PhoneNumberFormat
55

66
_LOCALE_NORMALIZATION_MAP = {"zh_TW": "zh_Hant", "zh_HK": "zh_Hant", "zh_MO": "zh_Hant"}
@@ -73,7 +73,7 @@ def prefix_description_for_number(data, longest_prefix, numobj, lang, script=Non
7373
Returns a text description in the given language code, for the given phone
7474
number's area, or an empty string if no description is available."""
7575
e164_num = format_number(numobj, PhoneNumberFormat.E164)
76-
if not e164_num.startswith('+'): # pragma no cover
76+
if not e164_num.startswith(U_PLUS): # pragma no cover
7777
# Can only hit this arm if there's an internal error in the rest of
7878
# the library
7979
raise Exception("Expect E164 number to start with +")

python/phonenumbers/timezone.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# See the License for the specific language governing permissions and
3535
# limitations under the License.
3636

37-
from .util import prnt, u
37+
from .util import prnt, u, U_PLUS
3838
from .phonenumberutil import PhoneNumberType, number_type
3939
from .phonenumberutil import PhoneNumberFormat, format_number
4040
from .prefix import prefix_description_for_number
@@ -73,7 +73,7 @@ def time_zones_for_geographical_number(numobj):
7373
with the default unknown time zone if no other time zone was found or if
7474
the number was invalid"""
7575
e164_num = format_number(numobj, PhoneNumberFormat.E164)
76-
if not e164_num.startswith('+'): # pragma no cover
76+
if not e164_num.startswith(U_PLUS): # pragma no cover
7777
# Can only hit this arm if there's an internal error in the rest of
7878
# the library
7979
raise Exception("Expect E164 number to start with +")

python/phonenumbers/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class UnicodeMixin(object): # pragma no cover
103103
U_SPACE = unicod(" ")
104104
U_DASH = unicod("-")
105105
U_TILDE = unicod("~")
106+
U_PLUS = unicod("+")
106107
U_ZERO = unicod("0")
107108
U_SLASH = unicod("/")
108109
U_SEMICOLON = unicod(";")

0 commit comments

Comments
 (0)