Permalink
Browse files

Try to sort out relative imports to make 2to3 work better

  • Loading branch information...
daviddrysdale committed Oct 25, 2011
1 parent 27cb8c8 commit 2fecd513a4be17fe2ff6d9ec3454df26a183d037
@@ -64,7 +64,7 @@
# Boilerplate header for individual region data files
_REGION_METADATA_PROLOG = '''"""Auto-generated file, do not edit by hand. %s metadata"""
from phonenumbers import NumberFormat, PhoneNumberDesc, PhoneMetadata
from phonenumbers.phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata
'''
# Copyright notice covering the XML metadata; include current year.
@@ -389,7 +389,7 @@ def emit_metadata_py(self, datadir):
print >> outfile, METADATA_FILE_PROLOG
print >> outfile, COPYRIGHT_NOTICE
for country_id in sorted(self.territory.keys()):
print >> outfile, "from region_%s import PHONE_METADATA_%s" % (country_id, country_id)
print >> outfile, "from .region_%s import PHONE_METADATA_%s" % (country_id, country_id)
# Emit the mapping from country code to region code
print >> outfile, _COUNTRY_CODE_TO_REGION_CODE_PROLOG
print >> outfile, "_COUNTRY_CODE_TO_REGION_CODE = {"
View
@@ -27,11 +27,11 @@ tests/testdata/__init__.py: ../resources/PhoneNumberMetaDataForTesting.xml buil
$(PYTHON) buildmetadatafromxml.py ../resources/PhoneNumberMetaDataForTesting.xml tests/testdata
test: alldata tests/testdata/__init__.py
$(PYTHON) phonenumbers/__init__.py
$(PYTHON) phonenumbers/re_util.py
$(PYTHON) phonenumbers/unicode_util.py
$(PYTHON) phonenumbers/geocoder.py
$(PYTHON) tests/__init__.py
$(PYTHON) -m phonenumbers.__init__
$(PYTHON) -m phonenumbers.re_util
$(PYTHON) -m phonenumbers.unicode_util
$(PYTHON) -m phonenumbers.geocoder
$(PYTHON) -m tests.__init__
# Coverage; requires coverage module
COVERAGE=$(shell hash python-coverage 2>&- && echo python-coverage || echo coverage)
@@ -131,6 +131,7 @@
'description_for_number',
'description_for_valid_number',
]
if __name__ == '__main__': # pragma no cover
import doctest
doctest.testmod()
@@ -26,13 +26,13 @@
# limitations under the License.
import re
import unicode_util
from re_util import fullmatch
from phonemetadata import PhoneMetadata
from phonenumberutil import _VALID_PUNCTUATION
from phonenumberutil import _PLUS_SIGN, _PLUS_CHARS_PATTERN
from phonenumberutil import _extract_country_code, region_code_for_country_code
from phonenumberutil import country_code_for_region
from .unicode_util import digit as unicode_digit
from .re_util import fullmatch
from .phonemetadata import PhoneMetadata
from .phonenumberutil import _VALID_PUNCTUATION
from .phonenumberutil import _PLUS_SIGN, _PLUS_CHARS_PATTERN
from .phonenumberutil import _extract_country_code, region_code_for_country_code
from .phonenumberutil import country_code_for_region
_EMPTY_METADATA = PhoneMetadata(id=u"", international_prefix=u"NA", register=False)
@@ -489,7 +489,7 @@ def _normalize_and_accrue_digits_and_plus_sign(self, next_char, remember_positio
normalized_char = next_char
self._accrued_input_without_formatting += next_char
else:
next_digit = unicode_util.digit(next_char, -1)
next_digit = unicode_digit(next_char, -1)
if next_digit != -1:
normalized_char = unicode(next_digit)
else: # pragma no cover
@@ -43,10 +43,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from phonenumberutil import format_number, PhoneNumberFormat, is_valid_number
from phonenumberutil import region_code_for_number
from geodata import GEOCODE_DATA, GEOCODE_LONGEST_PREFIX
from geodata.locale import LOCALE_DATA
from .phonenumberutil import format_number, PhoneNumberFormat, is_valid_number
from .phonenumberutil import region_code_for_number
from .geodata import GEOCODE_DATA, GEOCODE_LONGEST_PREFIX
from .geodata.locale import LOCALE_DATA
def _may_fall_back_to_english(lang):
@@ -16,7 +16,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from util import UnicodeMixin
from .util import UnicodeMixin
class NumberFormat(UnicodeMixin):
@@ -16,7 +16,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from util import UnicodeMixin
from .util import UnicodeMixin
class CountryCodeSource(object):
@@ -20,10 +20,10 @@
import re
# Extra regexp function; see README
from re_util import fullmatch
from util import UnicodeMixin
import unicode_util
import phonenumberutil
from .re_util import fullmatch
from .util import UnicodeMixin
from . import unicode_util
from . import phonenumberutil
def _limit(lower, upper):
@@ -30,17 +30,17 @@
# limitations under the License.
import re
from re_util import fullmatch # Extra regexp function; see README
from util import UnicodeMixin
import unicode_util
from .re_util import fullmatch # Extra regexp function; see README
from .util import UnicodeMixin
from .unicode_util import digit as unicode_digit
# Data class definitions
from phonenumber import PhoneNumber, CountryCodeSource
from phonemetadata import NumberFormat, PhoneMetadata
from .phonenumber import PhoneNumber, CountryCodeSource
from .phonemetadata import NumberFormat, PhoneMetadata
# Import auto-generated data structures
try:
from data import _COUNTRY_CODE_TO_REGION_CODE
from .data import _COUNTRY_CODE_TO_REGION_CODE
except ImportError: # pragma no cover
# Before the generated code exists, the data/ directory is empty.
# The generation process imports this module, creating a circular
@@ -485,7 +485,7 @@ def normalize_digits_only(number, keep_non_digits=False):
number_length = len(number)
normalized_digits = u""
for ii in xrange(number_length):
d = unicode_util.digit(number[ii], -1)
d = unicode_digit(number[ii], -1)
if d != -1:
normalized_digits += unicode(d)
elif keep_non_digits:
@@ -19,10 +19,10 @@
# limitations under the License.
import re
from re_util import fullmatch
from phonemetadata import PhoneMetadata
from phonenumberutil import _extract_possible_number, _PLUS_CHARS_PATTERN
from phonenumberutil import normalize_digits_only
from .re_util import fullmatch
from .phonemetadata import PhoneMetadata
from .phonenumberutil import _extract_possible_number, _PLUS_CHARS_PATTERN
from .phonenumberutil import normalize_digits_only
def connects_to_emergency_number(number, region_code):
@@ -22,7 +22,7 @@
from phonenumbers import PhoneMetadata, PhoneNumberDesc, NumberFormat
# Access internal functions of phonenumberutil.py
from phonenumbers import phonenumberutil
from phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
from .phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
class AsYouTypeFormatterTest(unittest.TestCase):
@@ -25,8 +25,8 @@
# Allow override library geocoding metadata with the test metadata.
REAL_GEOCODE_DATA = geocoder.GEOCODE_DATA
REAL_GEOCODE_LONGEST_PREFIX = geocoder.GEOCODE_LONGEST_PREFIX
from testgeodata import GEOCODE_DATA as TEST_GEOCODE_DATA
from testgeodata import GEOCODE_LONGEST_PREFIX as TEST_GEOCODE_LONGEST_PREFIX
from .testgeodata import GEOCODE_DATA as TEST_GEOCODE_DATA
from .testgeodata import GEOCODE_LONGEST_PREFIX as TEST_GEOCODE_LONGEST_PREFIX
def reinstate_real_geodata():
@@ -22,7 +22,7 @@
from phonenumbers import PhoneNumberMatch, PhoneNumberMatcher, Leniency
from phonenumbers import PhoneNumber, phonenumberutil
from phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
from .phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
class PhoneNumberMatchTest(unittest.TestCase):
@@ -35,7 +35,7 @@
# Import the test data; this will re-populate the
# PhoneMetadata.region_metadata map
from testdata import _COUNTRY_CODE_TO_REGION_CODE as TEST_CC_TO_RC
from .testdata import _COUNTRY_CODE_TO_REGION_CODE as TEST_CC_TO_RC
TEST_REGION_METADATA = PhoneMetadata.region_metadata
@@ -20,7 +20,7 @@
import unittest
from phonenumbers import connects_to_emergency_number
from phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
from .phonenumberutiltest import insert_test_metadata, reinstate_real_metadata
class ShortNumberUtilTest(unittest.TestCase):

0 comments on commit 2fecd51

Please sign in to comment.