Skip to content

Commit 2fecd51

Browse files
committed
Try to sort out relative imports to make 2to3 work better
1 parent 27cb8c8 commit 2fecd51

15 files changed

Lines changed: 43 additions & 42 deletions

python/buildmetadatafromxml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
# Boilerplate header for individual region data files
6666
_REGION_METADATA_PROLOG = '''"""Auto-generated file, do not edit by hand. %s metadata"""
67-
from phonenumbers import NumberFormat, PhoneNumberDesc, PhoneMetadata
67+
from phonenumbers.phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata
6868
'''
6969

7070
# Copyright notice covering the XML metadata; include current year.
@@ -389,7 +389,7 @@ def emit_metadata_py(self, datadir):
389389
print >> outfile, METADATA_FILE_PROLOG
390390
print >> outfile, COPYRIGHT_NOTICE
391391
for country_id in sorted(self.territory.keys()):
392-
print >> outfile, "from region_%s import PHONE_METADATA_%s" % (country_id, country_id)
392+
print >> outfile, "from .region_%s import PHONE_METADATA_%s" % (country_id, country_id)
393393
# Emit the mapping from country code to region code
394394
print >> outfile, _COUNTRY_CODE_TO_REGION_CODE_PROLOG
395395
print >> outfile, "_COUNTRY_CODE_TO_REGION_CODE = {"

python/makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ tests/testdata/__init__.py: ../resources/PhoneNumberMetaDataForTesting.xml buil
2727
$(PYTHON) buildmetadatafromxml.py ../resources/PhoneNumberMetaDataForTesting.xml tests/testdata
2828

2929
test: alldata tests/testdata/__init__.py
30-
$(PYTHON) phonenumbers/__init__.py
31-
$(PYTHON) phonenumbers/re_util.py
32-
$(PYTHON) phonenumbers/unicode_util.py
33-
$(PYTHON) phonenumbers/geocoder.py
34-
$(PYTHON) tests/__init__.py
30+
$(PYTHON) -m phonenumbers.__init__
31+
$(PYTHON) -m phonenumbers.re_util
32+
$(PYTHON) -m phonenumbers.unicode_util
33+
$(PYTHON) -m phonenumbers.geocoder
34+
$(PYTHON) -m tests.__init__
3535

3636
# Coverage; requires coverage module
3737
COVERAGE=$(shell hash python-coverage 2>&- && echo python-coverage || echo coverage)

python/phonenumbers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
'description_for_number',
132132
'description_for_valid_number',
133133
]
134+
134135
if __name__ == '__main__': # pragma no cover
135136
import doctest
136137
doctest.testmod()

python/phonenumbers/asyoutypeformatter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
# limitations under the License.
2727
import re
2828

29-
import unicode_util
30-
from re_util import fullmatch
31-
from phonemetadata import PhoneMetadata
32-
from phonenumberutil import _VALID_PUNCTUATION
33-
from phonenumberutil import _PLUS_SIGN, _PLUS_CHARS_PATTERN
34-
from phonenumberutil import _extract_country_code, region_code_for_country_code
35-
from phonenumberutil import country_code_for_region
29+
from .unicode_util import digit as unicode_digit
30+
from .re_util import fullmatch
31+
from .phonemetadata import PhoneMetadata
32+
from .phonenumberutil import _VALID_PUNCTUATION
33+
from .phonenumberutil import _PLUS_SIGN, _PLUS_CHARS_PATTERN
34+
from .phonenumberutil import _extract_country_code, region_code_for_country_code
35+
from .phonenumberutil import country_code_for_region
3636

3737
_EMPTY_METADATA = PhoneMetadata(id=u"", international_prefix=u"NA", register=False)
3838

@@ -489,7 +489,7 @@ def _normalize_and_accrue_digits_and_plus_sign(self, next_char, remember_positio
489489
normalized_char = next_char
490490
self._accrued_input_without_formatting += next_char
491491
else:
492-
next_digit = unicode_util.digit(next_char, -1)
492+
next_digit = unicode_digit(next_char, -1)
493493
if next_digit != -1:
494494
normalized_char = unicode(next_digit)
495495
else: # pragma no cover

python/phonenumbers/geocoder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
# See the License for the specific language governing permissions and
4444
# limitations under the License.
4545

46-
from phonenumberutil import format_number, PhoneNumberFormat, is_valid_number
47-
from phonenumberutil import region_code_for_number
48-
from geodata import GEOCODE_DATA, GEOCODE_LONGEST_PREFIX
49-
from geodata.locale import LOCALE_DATA
46+
from .phonenumberutil import format_number, PhoneNumberFormat, is_valid_number
47+
from .phonenumberutil import region_code_for_number
48+
from .geodata import GEOCODE_DATA, GEOCODE_LONGEST_PREFIX
49+
from .geodata.locale import LOCALE_DATA
5050

5151

5252
def _may_fall_back_to_english(lang):

python/phonenumbers/phonemetadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
19-
from util import UnicodeMixin
19+
from .util import UnicodeMixin
2020

2121

2222
class NumberFormat(UnicodeMixin):

python/phonenumbers/phonenumber.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
19-
from util import UnicodeMixin
19+
from .util import UnicodeMixin
2020

2121

2222
class CountryCodeSource(object):

python/phonenumbers/phonenumbermatcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import re
2121

2222
# Extra regexp function; see README
23-
from re_util import fullmatch
24-
from util import UnicodeMixin
25-
import unicode_util
26-
import phonenumberutil
23+
from .re_util import fullmatch
24+
from .util import UnicodeMixin
25+
from . import unicode_util
26+
from . import phonenumberutil
2727

2828

2929
def _limit(lower, upper):

python/phonenumbers/phonenumberutil.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
# limitations under the License.
3131
import re
3232

33-
from re_util import fullmatch # Extra regexp function; see README
34-
from util import UnicodeMixin
35-
import unicode_util
33+
from .re_util import fullmatch # Extra regexp function; see README
34+
from .util import UnicodeMixin
35+
from .unicode_util import digit as unicode_digit
3636

3737
# Data class definitions
38-
from phonenumber import PhoneNumber, CountryCodeSource
39-
from phonemetadata import NumberFormat, PhoneMetadata
38+
from .phonenumber import PhoneNumber, CountryCodeSource
39+
from .phonemetadata import NumberFormat, PhoneMetadata
4040

4141
# Import auto-generated data structures
4242
try:
43-
from data import _COUNTRY_CODE_TO_REGION_CODE
43+
from .data import _COUNTRY_CODE_TO_REGION_CODE
4444
except ImportError: # pragma no cover
4545
# Before the generated code exists, the data/ directory is empty.
4646
# The generation process imports this module, creating a circular
@@ -485,7 +485,7 @@ def normalize_digits_only(number, keep_non_digits=False):
485485
number_length = len(number)
486486
normalized_digits = u""
487487
for ii in xrange(number_length):
488-
d = unicode_util.digit(number[ii], -1)
488+
d = unicode_digit(number[ii], -1)
489489
if d != -1:
490490
normalized_digits += unicode(d)
491491
elif keep_non_digits:

python/phonenumbers/shortnumberutil.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
# limitations under the License.
2020
import re
2121

22-
from re_util import fullmatch
23-
from phonemetadata import PhoneMetadata
24-
from phonenumberutil import _extract_possible_number, _PLUS_CHARS_PATTERN
25-
from phonenumberutil import normalize_digits_only
22+
from .re_util import fullmatch
23+
from .phonemetadata import PhoneMetadata
24+
from .phonenumberutil import _extract_possible_number, _PLUS_CHARS_PATTERN
25+
from .phonenumberutil import normalize_digits_only
2626

2727

2828
def connects_to_emergency_number(number, region_code):

0 commit comments

Comments
 (0)