def _attempt_to_extract_ccc(self): """Extracts the country calling code from the beginning of _national_number to _prefix_before_national_number when they are available, and places the remaining input into _national_number. Returns True when a valid country calling code can be found. """ if len(self._national_number) == 0: return False number_without_ccc = "" country_code, number_without_ccc = _extract_country_code( self._national_number) if country_code == 0: return False self._national_number = number_without_ccc new_region_code = region_code_for_country_code(country_code) if new_region_code != self._default_country: self._current_metadata = PhoneMetadata.region_metadata.get( new_region_code, None) self._prefix_before_national_number += str(country_code) self._prefix_before_national_number += " " return True
def _get_metadata_for_region(region_code): """The metadata needed by this class is the same for all regions sharing the same country calling code. Therefore, we return the metadata for "main" region for this country calling code.""" country_calling_code = country_code_for_region(region_code) main_country = region_code_for_country_code(country_calling_code) # Set to a default instance of the metadata. This allows us to # function with an incorrect region code, even if formatting only # works for numbers specified with "+". return PhoneMetadata.region_metadata.get(main_country, _EMPTY_METADATA)
def _attempt_to_extract_ccc(self): """Extracts the country calling code from the beginning of _national_number to _prefix_before_national_number when they are available, and places the remaining input into _national_number. Returns True when a valid country calling code can be found. """ if len(self._national_number) == 0: return False number_without_ccc = "" country_code, number_without_ccc = _extract_country_code(self._national_number) if country_code == 0: return False self._national_number = number_without_ccc new_region_code = region_code_for_country_code(country_code) if new_region_code != self._default_country: self._current_metadata = _get_metadata_for_region(new_region_code) self._prefix_before_national_number += str(country_code) self._prefix_before_national_number += " " return True