|
37 | 37 | from .phonenumber import CountryCodeSource |
38 | 38 | from .phonemetadata import PhoneMetadata |
39 | 39 |
|
| 40 | +# Import auto-generated data structures |
| 41 | +try: |
| 42 | + from .data import _ALT_NUMBER_FORMATS |
| 43 | +except ImportError: # pragma no cover |
| 44 | + # Before the generated code exists, the data/ directory is empty. |
| 45 | + # The generation process imports this module, creating a circular |
| 46 | + # dependency. The hack below works around this. |
| 47 | + import os |
| 48 | + import sys |
| 49 | + if (os.path.basename(sys.argv[0]) == "buildmetadatafromxml.py" or |
| 50 | + os.path.basename(sys.argv[0]) == "buildgeocodingdata.py"): |
| 51 | + print >> sys.stderr, "Failed to import generated data (but OK as during autogeneration)" |
| 52 | + _ALT_NUMBER_FORMATS = {} |
| 53 | + else: |
| 54 | + raise |
| 55 | + |
40 | 56 |
|
41 | 57 | def _limit(lower, upper): |
42 | 58 | """Returns a regular expression quantifier with an upper and lower limit.""" |
@@ -312,9 +328,9 @@ def _check_number_grouping_is_valid(numobj, candidate, checker): |
312 | 328 | if checker(numobj, normalized_candidate, formatted_number_groups): |
313 | 329 | return True |
314 | 330 | # If this didn't pass, see if there are any alternate formats, and try them instead. |
315 | | - alternate_formats = None # TODO: write equivalent to: MetadataManager.getAlternateFormatsForCountry(numobj.country_code) |
| 331 | + alternate_formats = _ALT_NUMBER_FORMATS.get(numobj.country_code, None) |
316 | 332 | if alternate_formats is not None: |
317 | | - for alternate_format in alternate_formats.number_formats: |
| 333 | + for alternate_format in alternate_formats: |
318 | 334 | formatted_number_groups = _get_national_number_groups(numobj, alternate_format) |
319 | 335 | if checker(numobj, normalized_candidate, formatted_number_groups): |
320 | 336 | return True |
|
0 commit comments