(self, xterritory, short_data)
| 398 | class XTerritory(UnicodeMixin): |
| 399 | """Parse PhoneMetadata from XML element (territory)""" |
| 400 | def __init__(self, xterritory, short_data): |
| 401 | # Retrieve the REQUIRED attributes |
| 402 | id = xterritory.attrib['id'] |
| 403 | self.o = PhoneMetadata(id, short_data=short_data, register=False) |
| 404 | self.o._mutable = True |
| 405 | if 'countryCode' in xterritory.attrib: |
| 406 | self.o.country_code = int(xterritory.attrib['countryCode']) |
| 407 | else: |
| 408 | self.o.country_code = None |
| 409 | # Retrieve the IMPLIED attributes |
| 410 | self.o.international_prefix = xterritory.get('internationalPrefix', None) |
| 411 | self.o.leading_digits = xterritory.get('leadingDigits', None) |
| 412 | self.o.preferred_international_prefix = xterritory.get('preferredInternationalPrefix', None) |
| 413 | self.o.national_prefix = xterritory.get('nationalPrefix', None) |
| 414 | self.o.national_prefix_for_parsing = _dews_re(xterritory.get('nationalPrefixForParsing', None)) |
| 415 | self.o.national_prefix_transform_rule = xterritory.get('nationalPrefixTransformRule', None) |
| 416 | if self.o.national_prefix_transform_rule is not None: |
| 417 | # Replace '$1' etc with '\1' to match Python regexp group reference format |
| 418 | self.o.national_prefix_transform_rule = re.sub(r'\$', r'\\', self.o.national_prefix_transform_rule) |
| 419 | self.o.preferred_extn_prefix = xterritory.get('preferredExtnPrefix', None) |
| 420 | national_prefix_formatting_rule = xterritory.get('nationalPrefixFormattingRule', None) |
| 421 | national_prefix_optional_when_formatting = get_true_attrib(xterritory, 'nationalPrefixOptionalWhenFormatting') |
| 422 | carrier_code_formatting_rule = xterritory.get('carrierCodeFormattingRule', None) |
| 423 | |
| 424 | # Post-processing for the territory-default formatting rules. These are used |
| 425 | # in NumberFormat elements that don't supply their own formatting rules. |
| 426 | if self.o.national_prefix is not None: |
| 427 | if self.o.national_prefix_for_parsing is None: |
| 428 | # Default to self.national_prefix when national_prefix_for_parsing not set |
| 429 | self.o.national_prefix_for_parsing = self.o.national_prefix |
| 430 | national_prefix_formatting_rule = _expand_formatting_rule(national_prefix_formatting_rule, |
| 431 | self.o.national_prefix) |
| 432 | carrier_code_formatting_rule = _expand_formatting_rule(carrier_code_formatting_rule, |
| 433 | self.o.national_prefix) |
| 434 | self.o.main_country_for_code = get_true_attrib(xterritory, 'mainCountryForCode') |
| 435 | self.o.leading_zero_possible = get_true_attrib(xterritory, 'leadingZeroPossible') |
| 436 | self.o.mobile_number_portable_region = get_true_attrib(xterritory, 'mobileNumberPortableRegion') |
| 437 | |
| 438 | # Retrieve the various PhoneNumberDesc elements, which have one of the forms: |
| 439 | # (possibleLengths, exampleNumber, nationalNumberPattern) |
| 440 | # (possibleLengths, nationalNumberPattern) |
| 441 | # (nationalNumberPattern) |
| 442 | |
| 443 | # The general_desc is first and special; it is used to fill out missing fields |
| 444 | # in many of the other PhoneNumberDesc elements. |
| 445 | self.o.general_desc = XPhoneNumberDesc(xterritory, 'generalDesc', has_possible_lengths=False, has_example_number=False).o |
| 446 | |
| 447 | self.o.toll_free = XPhoneNumberDesc(xterritory, 'tollFree', template=self.o.general_desc).o |
| 448 | self.o.premium_rate = XPhoneNumberDesc(xterritory, 'premiumRate', template=self.o.general_desc).o |
| 449 | if not short_data: |
| 450 | # Mobile and fixed-line descriptions do not inherit anything from the general_desc |
| 451 | self.o.fixed_line = XPhoneNumberDesc(xterritory, 'fixedLine').o |
| 452 | self.o.mobile = XPhoneNumberDesc(xterritory, 'mobile').o |
| 453 | |
| 454 | self.o.pager = XPhoneNumberDesc(xterritory, 'pager', template=self.o.general_desc).o |
| 455 | self.o.shared_cost = XPhoneNumberDesc(xterritory, 'sharedCost', template=self.o.general_desc).o |
| 456 | self.o.personal_number = XPhoneNumberDesc(xterritory, 'personalNumber', template=self.o.general_desc).o |
| 457 | self.o.voip = XPhoneNumberDesc(xterritory, 'voip', template=self.o.general_desc).o |
nothing calls this directly
no test coverage detected