id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
220,800
daviddrysdale/python-phonenumbers
python/phonenumbers/asyoutypeformatter.py
AsYouTypeFormatter._is_nanpa_number_with_national_prefix
def _is_nanpa_number_with_national_prefix(self): """Returns true if the current country is a NANPA country and the national number begins with the national prefix. """ # For NANPA numbers beginning with 1[2-9], treat the 1 as the national # prefix. The reason is that national sig...
python
def _is_nanpa_number_with_national_prefix(self): """Returns true if the current country is a NANPA country and the national number begins with the national prefix. """ # For NANPA numbers beginning with 1[2-9], treat the 1 as the national # prefix. The reason is that national sig...
[ "def", "_is_nanpa_number_with_national_prefix", "(", "self", ")", ":", "# For NANPA numbers beginning with 1[2-9], treat the 1 as the national", "# prefix. The reason is that national significant numbers in NANPA", "# always start with [2-9] after the national prefix. Numbers", "# beginning with ...
Returns true if the current country is a NANPA country and the national number begins with the national prefix.
[ "Returns", "true", "if", "the", "current", "country", "is", "a", "NANPA", "country", "and", "the", "national", "number", "begins", "with", "the", "national", "prefix", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/asyoutypeformatter.py#L466-L476
220,801
daviddrysdale/python-phonenumbers
python/phonenumbers/asyoutypeformatter.py
AsYouTypeFormatter._attempt_to_extract_idd
def _attempt_to_extract_idd(self): """Extracts IDD and plus sign to self._prefix_before_national_number when they are available, and places the remaining input into _national_number. Returns True when accrued_input_without_formatting begins with the plus sign or valid IDD for de...
python
def _attempt_to_extract_idd(self): """Extracts IDD and plus sign to self._prefix_before_national_number when they are available, and places the remaining input into _national_number. Returns True when accrued_input_without_formatting begins with the plus sign or valid IDD for de...
[ "def", "_attempt_to_extract_idd", "(", "self", ")", ":", "international_prefix", "=", "re", ".", "compile", "(", "unicod", "(", "\"\\\\\"", ")", "+", "_PLUS_SIGN", "+", "unicod", "(", "\"|\"", ")", "+", "(", "self", ".", "_current_metadata", ".", "internatio...
Extracts IDD and plus sign to self._prefix_before_national_number when they are available, and places the remaining input into _national_number. Returns True when accrued_input_without_formatting begins with the plus sign or valid IDD for default_country.
[ "Extracts", "IDD", "and", "plus", "sign", "to", "self", ".", "_prefix_before_national_number", "when", "they", "are", "available", "and", "places", "the", "remaining", "input", "into", "_national_number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/asyoutypeformatter.py#L501-L520
220,802
daviddrysdale/python-phonenumbers
python/phonenumbers/asyoutypeformatter.py
AsYouTypeFormatter._attempt_to_extract_ccc
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. ...
python
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. ...
[ "def", "_attempt_to_extract_ccc", "(", "self", ")", ":", "if", "len", "(", "self", ".", "_national_number", ")", "==", "0", ":", "return", "False", "country_code", ",", "number_without_ccc", "=", "_extract_country_code", "(", "self", ".", "_national_number", ")"...
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.
[ "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", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/asyoutypeformatter.py#L522-L548
220,803
daviddrysdale/python-phonenumbers
python/phonenumbers/geocoder.py
country_name_for_number
def country_name_for_number(numobj, lang, script=None, region=None): """Returns the customary display name in the given langauge for the given territory the given PhoneNumber object is from. If it could be from many territories, nothing is returned. Arguments: numobj -- The PhoneNumber object for ...
python
def country_name_for_number(numobj, lang, script=None, region=None): """Returns the customary display name in the given langauge for the given territory the given PhoneNumber object is from. If it could be from many territories, nothing is returned. Arguments: numobj -- The PhoneNumber object for ...
[ "def", "country_name_for_number", "(", "numobj", ",", "lang", ",", "script", "=", "None", ",", "region", "=", "None", ")", ":", "region_codes", "=", "region_codes_for_country_code", "(", "numobj", ".", "country_code", ")", "if", "len", "(", "region_codes", ")"...
Returns the customary display name in the given langauge for the given territory the given PhoneNumber object is from. If it could be from many territories, nothing is returned. Arguments: numobj -- The PhoneNumber object for which we want to get a text description. lang -- A 2-letter lowercase IS...
[ "Returns", "the", "customary", "display", "name", "in", "the", "given", "langauge", "for", "the", "given", "territory", "the", "given", "PhoneNumber", "object", "is", "from", ".", "If", "it", "could", "be", "from", "many", "territories", "nothing", "is", "re...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/geocoder.py#L75-L106
220,804
daviddrysdale/python-phonenumbers
python/phonenumbers/geocoder.py
description_for_valid_number
def description_for_valid_number(numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber object, in the language provided. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number ...
python
def description_for_valid_number(numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber object, in the language provided. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number ...
[ "def", "description_for_valid_number", "(", "numobj", ",", "lang", ",", "script", "=", "None", ",", "region", "=", "None", ")", ":", "number_region", "=", "region_code_for_number", "(", "numobj", ")", "if", "region", "is", "None", "or", "region", "==", "numb...
Return a text description of a PhoneNumber object, in the language provided. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number is from if more detailed information is available. If the phone number is f...
[ "Return", "a", "text", "description", "of", "a", "PhoneNumber", "object", "in", "the", "language", "provided", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/geocoder.py#L122-L189
220,805
daviddrysdale/python-phonenumbers
python/phonenumbers/geocoder.py
description_for_number
def description_for_number(numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber object for the given language. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number is from. Th...
python
def description_for_number(numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber object for the given language. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number is from. Th...
[ "def", "description_for_number", "(", "numobj", ",", "lang", ",", "script", "=", "None", ",", "region", "=", "None", ")", ":", "ntype", "=", "number_type", "(", "numobj", ")", "if", "ntype", "==", "PhoneNumberType", ".", "UNKNOWN", ":", "return", "\"\"", ...
Return a text description of a PhoneNumber object for the given language. The description might consist of the name of the country where the phone number is from and/or the name of the geographical area the phone number is from. This function explicitly checks the validity of the number passed in Arg...
[ "Return", "a", "text", "description", "of", "a", "PhoneNumber", "object", "for", "the", "given", "language", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/geocoder.py#L194-L220
220,806
daviddrysdale/python-phonenumbers
python/phonenumbers/prefix.py
_find_lang
def _find_lang(langdict, lang, script, region): """Return the entry in the dictionary for the given language information.""" # Check if we should map this to a different locale. full_locale = _full_locale(lang, script, region) if (full_locale in _LOCALE_NORMALIZATION_MAP and _LOCALE_NORMALIZATIO...
python
def _find_lang(langdict, lang, script, region): """Return the entry in the dictionary for the given language information.""" # Check if we should map this to a different locale. full_locale = _full_locale(lang, script, region) if (full_locale in _LOCALE_NORMALIZATION_MAP and _LOCALE_NORMALIZATIO...
[ "def", "_find_lang", "(", "langdict", ",", "lang", ",", "script", ",", "region", ")", ":", "# Check if we should map this to a different locale.", "full_locale", "=", "_full_locale", "(", "lang", ",", "script", ",", "region", ")", "if", "(", "full_locale", "in", ...
Return the entry in the dictionary for the given language information.
[ "Return", "the", "entry", "in", "the", "dictionary", "for", "the", "given", "language", "information", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/prefix.py#L29-L56
220,807
daviddrysdale/python-phonenumbers
python/phonenumbers/prefix.py
_prefix_description_for_number
def _prefix_description_for_number(data, longest_prefix, numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber for the given language. Arguments: data -- Prefix dictionary to lookup up number in. longest_prefix -- Length of the longest key in data. numobj -- The Pho...
python
def _prefix_description_for_number(data, longest_prefix, numobj, lang, script=None, region=None): """Return a text description of a PhoneNumber for the given language. Arguments: data -- Prefix dictionary to lookup up number in. longest_prefix -- Length of the longest key in data. numobj -- The Pho...
[ "def", "_prefix_description_for_number", "(", "data", ",", "longest_prefix", ",", "numobj", ",", "lang", ",", "script", "=", "None", ",", "region", "=", "None", ")", ":", "e164_num", "=", "format_number", "(", "numobj", ",", "PhoneNumberFormat", ".", "E164", ...
Return a text description of a PhoneNumber for the given language. Arguments: data -- Prefix dictionary to lookup up number in. longest_prefix -- Length of the longest key in data. numobj -- The PhoneNumber object for which we want to get a text description. lang -- A 2-letter lowercase ISO 639-1 l...
[ "Return", "a", "text", "description", "of", "a", "PhoneNumber", "for", "the", "given", "language", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/prefix.py#L59-L90
220,808
daviddrysdale/python-phonenumbers
python/phonenumbers/phonemetadata.py
NumberFormat.merge_from
def merge_from(self, other): """Merge information from another NumberFormat object into this one.""" if other.pattern is not None: self.pattern = other.pattern if other.format is not None: self.format = other.format self.leading_digits_pattern.extend(other.leading...
python
def merge_from(self, other): """Merge information from another NumberFormat object into this one.""" if other.pattern is not None: self.pattern = other.pattern if other.format is not None: self.format = other.format self.leading_digits_pattern.extend(other.leading...
[ "def", "merge_from", "(", "self", ",", "other", ")", ":", "if", "other", ".", "pattern", "is", "not", "None", ":", "self", ".", "pattern", "=", "other", ".", "pattern", "if", "other", ".", "format", "is", "not", "None", ":", "self", ".", "format", ...
Merge information from another NumberFormat object into this one.
[ "Merge", "information", "from", "another", "NumberFormat", "object", "into", "this", "one", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonemetadata.py#L107-L119
220,809
daviddrysdale/python-phonenumbers
python/phonenumbers/phonemetadata.py
PhoneNumberDesc.merge_from
def merge_from(self, other): """Merge information from another PhoneNumberDesc object into this one.""" if other.national_number_pattern is not None: self.national_number_pattern = other.national_number_pattern if other.example_number is not None: self.example_number = ot...
python
def merge_from(self, other): """Merge information from another PhoneNumberDesc object into this one.""" if other.national_number_pattern is not None: self.national_number_pattern = other.national_number_pattern if other.example_number is not None: self.example_number = ot...
[ "def", "merge_from", "(", "self", ",", "other", ")", ":", "if", "other", ".", "national_number_pattern", "is", "not", "None", ":", "self", ".", "national_number_pattern", "=", "other", ".", "national_number_pattern", "if", "other", ".", "example_number", "is", ...
Merge information from another PhoneNumberDesc object into this one.
[ "Merge", "information", "from", "another", "PhoneNumberDesc", "object", "into", "this", "one", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonemetadata.py#L193-L198
220,810
daviddrysdale/python-phonenumbers
python/phonenumbers/phonemetadata.py
PhoneMetadata.load_all
def load_all(kls): """Force immediate load of all metadata""" # Force expansion of contents to lists because we invalidate the iterator for region_code, loader in list(kls._region_available.items()): if loader is not None: # pragma no cover loader(region_code) ...
python
def load_all(kls): """Force immediate load of all metadata""" # Force expansion of contents to lists because we invalidate the iterator for region_code, loader in list(kls._region_available.items()): if loader is not None: # pragma no cover loader(region_code) ...
[ "def", "load_all", "(", "kls", ")", ":", "# Force expansion of contents to lists because we invalidate the iterator", "for", "region_code", ",", "loader", "in", "list", "(", "kls", ".", "_region_available", ".", "items", "(", ")", ")", ":", "if", "loader", "is", "...
Force immediate load of all metadata
[ "Force", "immediate", "load", "of", "all", "metadata" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonemetadata.py#L317-L327
220,811
daviddrysdale/python-phonenumbers
python/phonenumbers/pb2/__init__.py
PBToPy
def PBToPy(numpb): """Convert phonenumber_pb2.PhoneNumber to phonenumber.PhoneNumber""" return PhoneNumber(country_code=numpb.country_code if numpb.HasField("country_code") else None, national_number=numpb.national_number if numpb.HasField("national_number") else None, ...
python
def PBToPy(numpb): """Convert phonenumber_pb2.PhoneNumber to phonenumber.PhoneNumber""" return PhoneNumber(country_code=numpb.country_code if numpb.HasField("country_code") else None, national_number=numpb.national_number if numpb.HasField("national_number") else None, ...
[ "def", "PBToPy", "(", "numpb", ")", ":", "return", "PhoneNumber", "(", "country_code", "=", "numpb", ".", "country_code", "if", "numpb", ".", "HasField", "(", "\"country_code\"", ")", "else", "None", ",", "national_number", "=", "numpb", ".", "national_number"...
Convert phonenumber_pb2.PhoneNumber to phonenumber.PhoneNumber
[ "Convert", "phonenumber_pb2", ".", "PhoneNumber", "to", "phonenumber", ".", "PhoneNumber" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/pb2/__init__.py#L42-L51
220,812
daviddrysdale/python-phonenumbers
python/phonenumbers/pb2/__init__.py
PyToPB
def PyToPB(numobj): """Convert phonenumber.PhoneNumber to phonenumber_pb2.PhoneNumber""" numpb = PhoneNumberPB() if numobj.country_code is not None: numpb.country_code = numobj.country_code if numobj.national_number is not None: numpb.national_number = numobj.national_number if numob...
python
def PyToPB(numobj): """Convert phonenumber.PhoneNumber to phonenumber_pb2.PhoneNumber""" numpb = PhoneNumberPB() if numobj.country_code is not None: numpb.country_code = numobj.country_code if numobj.national_number is not None: numpb.national_number = numobj.national_number if numob...
[ "def", "PyToPB", "(", "numobj", ")", ":", "numpb", "=", "PhoneNumberPB", "(", ")", "if", "numobj", ".", "country_code", "is", "not", "None", ":", "numpb", ".", "country_code", "=", "numobj", ".", "country_code", "if", "numobj", ".", "national_number", "is"...
Convert phonenumber.PhoneNumber to phonenumber_pb2.PhoneNumber
[ "Convert", "phonenumber", ".", "PhoneNumber", "to", "phonenumber_pb2", ".", "PhoneNumber" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/pb2/__init__.py#L53-L71
220,813
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
_get_unique_child
def _get_unique_child(xtag, eltname): """Get the unique child element under xtag with name eltname""" try: results = xtag.findall(eltname) if len(results) > 1: raise Exception("Multiple elements found where 0/1 expected") elif len(results) == 1: return results[0] ...
python
def _get_unique_child(xtag, eltname): """Get the unique child element under xtag with name eltname""" try: results = xtag.findall(eltname) if len(results) > 1: raise Exception("Multiple elements found where 0/1 expected") elif len(results) == 1: return results[0] ...
[ "def", "_get_unique_child", "(", "xtag", ",", "eltname", ")", ":", "try", ":", "results", "=", "xtag", ".", "findall", "(", "eltname", ")", "if", "len", "(", "results", ")", ">", "1", ":", "raise", "Exception", "(", "\"Multiple elements found where 0/1 expec...
Get the unique child element under xtag with name eltname
[ "Get", "the", "unique", "child", "element", "under", "xtag", "with", "name", "eltname" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L116-L127
220,814
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
_get_unique_child_value
def _get_unique_child_value(xtag, eltname): """Get the text content of the unique child element under xtag with name eltname""" xelt = _get_unique_child(xtag, eltname) if xelt is None: return None else: return xelt.text
python
def _get_unique_child_value(xtag, eltname): """Get the text content of the unique child element under xtag with name eltname""" xelt = _get_unique_child(xtag, eltname) if xelt is None: return None else: return xelt.text
[ "def", "_get_unique_child_value", "(", "xtag", ",", "eltname", ")", ":", "xelt", "=", "_get_unique_child", "(", "xtag", ",", "eltname", ")", "if", "xelt", "is", "None", ":", "return", "None", "else", ":", "return", "xelt", ".", "text" ]
Get the text content of the unique child element under xtag with name eltname
[ "Get", "the", "text", "content", "of", "the", "unique", "child", "element", "under", "xtag", "with", "name", "eltname" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L130-L136
220,815
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
_extract_lengths
def _extract_lengths(ll): """Extract list of possible lengths from string""" results = set() if ll is None: return [] for val in ll.split(','): m = _NUM_RE.match(val) if m: results.add(int(val)) else: m = _RANGE_RE.match(val) if m is No...
python
def _extract_lengths(ll): """Extract list of possible lengths from string""" results = set() if ll is None: return [] for val in ll.split(','): m = _NUM_RE.match(val) if m: results.add(int(val)) else: m = _RANGE_RE.match(val) if m is No...
[ "def", "_extract_lengths", "(", "ll", ")", ":", "results", "=", "set", "(", ")", "if", "ll", "is", "None", ":", "return", "[", "]", "for", "val", "in", "ll", ".", "split", "(", "','", ")", ":", "m", "=", "_NUM_RE", ".", "match", "(", "val", ")"...
Extract list of possible lengths from string
[ "Extract", "list", "of", "possible", "lengths", "from", "string" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L169-L186
220,816
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
_standalone
def _standalone(argv): """Parse the given XML file and emit generated code.""" alternate = None short_data = False try: opts, args = getopt.getopt(argv, "hlsa:", ("help", "lax", "short", "alt=")) except getopt.GetoptError: prnt(__doc__, file=sys.stderr) sys.exit(1) for op...
python
def _standalone(argv): """Parse the given XML file and emit generated code.""" alternate = None short_data = False try: opts, args = getopt.getopt(argv, "hlsa:", ("help", "lax", "short", "alt=")) except getopt.GetoptError: prnt(__doc__, file=sys.stderr) sys.exit(1) for op...
[ "def", "_standalone", "(", "argv", ")", ":", "alternate", "=", "None", "short_data", "=", "False", "try", ":", "opts", ",", "args", "=", "getopt", ".", "getopt", "(", "argv", ",", "\"hlsa:\"", ",", "(", "\"help\"", ",", "\"lax\"", ",", "\"short\"", ","...
Parse the given XML file and emit generated code.
[ "Parse", "the", "given", "XML", "file", "and", "emit", "generated", "code", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L670-L701
220,817
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
XPhoneNumberMetadata.add_alternate_formats
def add_alternate_formats(self, filename): """Add phone number alternate format metadata retrieved from XML""" with open(filename, "r") as infile: xtree = etree.parse(infile) self.alt_territory = {} # country_code to XAlternateTerritory xterritories = xtree.find(TOP_XPATH) ...
python
def add_alternate_formats(self, filename): """Add phone number alternate format metadata retrieved from XML""" with open(filename, "r") as infile: xtree = etree.parse(infile) self.alt_territory = {} # country_code to XAlternateTerritory xterritories = xtree.find(TOP_XPATH) ...
[ "def", "add_alternate_formats", "(", "self", ",", "filename", ")", ":", "with", "open", "(", "filename", ",", "\"r\"", ")", "as", "infile", ":", "xtree", "=", "etree", ".", "parse", "(", "infile", ")", "self", ".", "alt_territory", "=", "{", "}", "# co...
Add phone number alternate format metadata retrieved from XML
[ "Add", "phone", "number", "alternate", "format", "metadata", "retrieved", "from", "XML" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L567-L581
220,818
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
XPhoneNumberMetadata.emit_metadata_for_region_py
def emit_metadata_for_region_py(self, region, region_filename, module_prefix): """Emit Python code generating the metadata for the given region""" terrobj = self.territory[region] with open(region_filename, "w") as outfile: prnt(_REGION_METADATA_PROLOG % {'region': terrobj.identifier...
python
def emit_metadata_for_region_py(self, region, region_filename, module_prefix): """Emit Python code generating the metadata for the given region""" terrobj = self.territory[region] with open(region_filename, "w") as outfile: prnt(_REGION_METADATA_PROLOG % {'region': terrobj.identifier...
[ "def", "emit_metadata_for_region_py", "(", "self", ",", "region", ",", "region_filename", ",", "module_prefix", ")", ":", "terrobj", "=", "self", ".", "territory", "[", "region", "]", "with", "open", "(", "region_filename", ",", "\"w\"", ")", "as", "outfile", ...
Emit Python code generating the metadata for the given region
[ "Emit", "Python", "code", "generating", "the", "metadata", "for", "the", "given", "region" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L586-L591
220,819
daviddrysdale/python-phonenumbers
tools/python/buildmetadatafromxml.py
XPhoneNumberMetadata.emit_alt_formats_for_cc_py
def emit_alt_formats_for_cc_py(self, cc, cc_filename, module_prefix): """Emit Python code generating the alternate format metadata for the given country code""" terrobj = self.alt_territory[cc] with open(cc_filename, "w") as outfile: prnt(_ALT_FORMAT_METADATA_PROLOG % (cc, module_pre...
python
def emit_alt_formats_for_cc_py(self, cc, cc_filename, module_prefix): """Emit Python code generating the alternate format metadata for the given country code""" terrobj = self.alt_territory[cc] with open(cc_filename, "w") as outfile: prnt(_ALT_FORMAT_METADATA_PROLOG % (cc, module_pre...
[ "def", "emit_alt_formats_for_cc_py", "(", "self", ",", "cc", ",", "cc_filename", ",", "module_prefix", ")", ":", "terrobj", "=", "self", ".", "alt_territory", "[", "cc", "]", "with", "open", "(", "cc_filename", ",", "\"w\"", ")", "as", "outfile", ":", "prn...
Emit Python code generating the alternate format metadata for the given country code
[ "Emit", "Python", "code", "generating", "the", "alternate", "format", "metadata", "for", "the", "given", "country", "code" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildmetadatafromxml.py#L593-L598
220,820
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_create_extn_pattern
def _create_extn_pattern(single_extn_symbols): """Helper initialiser method to create the regular-expression pattern to match extensions, allowing the one-char extension symbols provided by single_extn_symbols.""" # There are three regular expressions here. The first covers RFC 3966 # format, where ...
python
def _create_extn_pattern(single_extn_symbols): """Helper initialiser method to create the regular-expression pattern to match extensions, allowing the one-char extension symbols provided by single_extn_symbols.""" # There are three regular expressions here. The first covers RFC 3966 # format, where ...
[ "def", "_create_extn_pattern", "(", "single_extn_symbols", ")", ":", "# There are three regular expressions here. The first covers RFC 3966", "# format, where the extension is added using \";ext=\". The second more", "# generic one starts with optional white space and ends with an optional", "# fu...
Helper initialiser method to create the regular-expression pattern to match extensions, allowing the one-char extension symbols provided by single_extn_symbols.
[ "Helper", "initialiser", "method", "to", "create", "the", "regular", "-", "expression", "pattern", "to", "match", "extensions", "allowing", "the", "one", "-", "char", "extension", "symbols", "provided", "by", "single_extn_symbols", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L302-L323
220,821
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_copy_number_format
def _copy_number_format(other): """Return a mutable copy of the given NumberFormat object""" copy = NumberFormat(pattern=other.pattern, format=other.format, leading_digits_pattern=list(other.leading_digits_pattern), national_prefix_formatti...
python
def _copy_number_format(other): """Return a mutable copy of the given NumberFormat object""" copy = NumberFormat(pattern=other.pattern, format=other.format, leading_digits_pattern=list(other.leading_digits_pattern), national_prefix_formatti...
[ "def", "_copy_number_format", "(", "other", ")", ":", "copy", "=", "NumberFormat", "(", "pattern", "=", "other", ".", "pattern", ",", "format", "=", "other", ".", "format", ",", "leading_digits_pattern", "=", "list", "(", "other", ".", "leading_digits_pattern"...
Return a mutable copy of the given NumberFormat object
[ "Return", "a", "mutable", "copy", "of", "the", "given", "NumberFormat", "object" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L497-L506
220,822
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_extract_possible_number
def _extract_possible_number(number): """Attempt to extract a possible number from the string passed in. This currently strips all leading characters that cannot be used to start a phone number. Characters that can be used to start a phone number are defined in the VALID_START_CHAR_PATTERN. If none of ...
python
def _extract_possible_number(number): """Attempt to extract a possible number from the string passed in. This currently strips all leading characters that cannot be used to start a phone number. Characters that can be used to start a phone number are defined in the VALID_START_CHAR_PATTERN. If none of ...
[ "def", "_extract_possible_number", "(", "number", ")", ":", "match", "=", "_VALID_START_CHAR_PATTERN", ".", "search", "(", "number", ")", "if", "match", ":", "number", "=", "number", "[", "match", ".", "start", "(", ")", ":", "]", "# Remove trailing non-alpha ...
Attempt to extract a possible number from the string passed in. This currently strips all leading characters that cannot be used to start a phone number. Characters that can be used to start a phone number are defined in the VALID_START_CHAR_PATTERN. If none of these characters are found in the number ...
[ "Attempt", "to", "extract", "a", "possible", "number", "from", "the", "string", "passed", "in", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L509-L542
220,823
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_viable_phone_number
def _is_viable_phone_number(number): """Checks to see if a string could possibly be a phone number. At the moment, checks to see that the string begins with at least 2 digits, ignoring any punctuation commonly found in phone numbers. This method does not require the number to be normalized in advance ...
python
def _is_viable_phone_number(number): """Checks to see if a string could possibly be a phone number. At the moment, checks to see that the string begins with at least 2 digits, ignoring any punctuation commonly found in phone numbers. This method does not require the number to be normalized in advance ...
[ "def", "_is_viable_phone_number", "(", "number", ")", ":", "if", "len", "(", "number", ")", "<", "_MIN_LENGTH_FOR_NSN", ":", "return", "False", "match", "=", "fullmatch", "(", "_VALID_PHONE_NUMBER_PATTERN", ",", "number", ")", "return", "bool", "(", "match", "...
Checks to see if a string could possibly be a phone number. At the moment, checks to see that the string begins with at least 2 digits, ignoring any punctuation commonly found in phone numbers. This method does not require the number to be normalized in advance - but does assume that leading non-numbe...
[ "Checks", "to", "see", "if", "a", "string", "could", "possibly", "be", "a", "phone", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L545-L563
220,824
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
length_of_geographical_area_code
def length_of_geographical_area_code(numobj): """Return length of the geographical area code for a number. Gets the length of the geographical area code from the PhoneNumber object passed in, so that clients could use it to split a national significant number into geographical area code and subscriber ...
python
def length_of_geographical_area_code(numobj): """Return length of the geographical area code for a number. Gets the length of the geographical area code from the PhoneNumber object passed in, so that clients could use it to split a national significant number into geographical area code and subscriber ...
[ "def", "length_of_geographical_area_code", "(", "numobj", ")", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code_for_number", "(", "numobj", ")", ",", "None", ")", "if", "metadata", "is", "None", ":", "return", "0", "# If a count...
Return length of the geographical area code for a number. Gets the length of the geographical area code from the PhoneNumber object passed in, so that clients could use it to split a national significant number into geographical area code and subscriber number. It works in such a way that the resultant...
[ "Return", "length", "of", "the", "geographical", "area", "code", "for", "a", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L638-L701
220,825
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
length_of_national_destination_code
def length_of_national_destination_code(numobj): """Return length of the national destination code code for a number. Gets the length of the national destination code (NDC) from the PhoneNumber object passed in, so that clients could use it to split a national significant number into NDC and subscriber...
python
def length_of_national_destination_code(numobj): """Return length of the national destination code code for a number. Gets the length of the national destination code (NDC) from the PhoneNumber object passed in, so that clients could use it to split a national significant number into NDC and subscriber...
[ "def", "length_of_national_destination_code", "(", "numobj", ")", ":", "if", "numobj", ".", "extension", "is", "not", "None", ":", "# We don't want to alter the object given to us, but we don't want to", "# include the extension when we format it, so we copy it and clear the", "# ext...
Return length of the national destination code code for a number. Gets the length of the national destination code (NDC) from the PhoneNumber object passed in, so that clients could use it to split a national significant number into NDC and subscriber number. The NDC of a phone number is normally the f...
[ "Return", "length", "of", "the", "national", "destination", "code", "code", "for", "a", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L704-L769
220,826
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_normalize_helper
def _normalize_helper(number, replacements, remove_non_matches): """Normalizes a string of characters representing a phone number by replacing all characters found in the accompanying map with the values therein, and stripping all other characters if remove_non_matches is true. Arguments: number --...
python
def _normalize_helper(number, replacements, remove_non_matches): """Normalizes a string of characters representing a phone number by replacing all characters found in the accompanying map with the values therein, and stripping all other characters if remove_non_matches is true. Arguments: number --...
[ "def", "_normalize_helper", "(", "number", ",", "replacements", ",", "remove_non_matches", ")", ":", "normalized_number", "=", "[", "]", "for", "char", "in", "number", ":", "new_digit", "=", "replacements", ".", "get", "(", "char", ".", "upper", "(", ")", ...
Normalizes a string of characters representing a phone number by replacing all characters found in the accompanying map with the values therein, and stripping all other characters if remove_non_matches is true. Arguments: number -- a string representing a phone number replacements -- a mapping of c...
[ "Normalizes", "a", "string", "of", "characters", "representing", "a", "phone", "number", "by", "replacing", "all", "characters", "found", "in", "the", "accompanying", "map", "with", "the", "values", "therein", "and", "stripping", "all", "other", "characters", "i...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L784-L807
220,827
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_desc_has_data
def _desc_has_data(desc): """Returns true if there is any data set for a particular PhoneNumberDesc.""" if desc is None: return False # Checking most properties since we don't know what's present, since a custom build may have # stripped just one of them (e.g. liteBuild strips exampleNumber). We...
python
def _desc_has_data(desc): """Returns true if there is any data set for a particular PhoneNumberDesc.""" if desc is None: return False # Checking most properties since we don't know what's present, since a custom build may have # stripped just one of them (e.g. liteBuild strips exampleNumber). We...
[ "def", "_desc_has_data", "(", "desc", ")", ":", "if", "desc", "is", "None", ":", "return", "False", "# Checking most properties since we don't know what's present, since a custom build may have", "# stripped just one of them (e.g. liteBuild strips exampleNumber). We don't bother checking...
Returns true if there is any data set for a particular PhoneNumberDesc.
[ "Returns", "true", "if", "there", "is", "any", "data", "set", "for", "a", "particular", "PhoneNumberDesc", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L836-L846
220,828
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_supported_types_for_metadata
def _supported_types_for_metadata(metadata): """Returns the types we have metadata for based on the PhoneMetadata object passed in, which must be non-None.""" numtypes = set() for numtype in PhoneNumberType.values(): if numtype in (PhoneNumberType.FIXED_LINE_OR_MOBILE, PhoneNumberType.UNKNOWN): ...
python
def _supported_types_for_metadata(metadata): """Returns the types we have metadata for based on the PhoneMetadata object passed in, which must be non-None.""" numtypes = set() for numtype in PhoneNumberType.values(): if numtype in (PhoneNumberType.FIXED_LINE_OR_MOBILE, PhoneNumberType.UNKNOWN): ...
[ "def", "_supported_types_for_metadata", "(", "metadata", ")", ":", "numtypes", "=", "set", "(", ")", "for", "numtype", "in", "PhoneNumberType", ".", "values", "(", ")", ":", "if", "numtype", "in", "(", "PhoneNumberType", ".", "FIXED_LINE_OR_MOBILE", ",", "Phon...
Returns the types we have metadata for based on the PhoneMetadata object passed in, which must be non-None.
[ "Returns", "the", "types", "we", "have", "metadata", "for", "based", "on", "the", "PhoneMetadata", "object", "passed", "in", "which", "must", "be", "non", "-", "None", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L849-L859
220,829
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
supported_types_for_region
def supported_types_for_region(region_code): """Returns the types for a given region which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE (if numbers in this region could be classified as FIXED_LINE_OR_MOBILE, both FIXED_LINE and MOBILE would be present) and UNKNOWN. No types ...
python
def supported_types_for_region(region_code): """Returns the types for a given region which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE (if numbers in this region could be classified as FIXED_LINE_OR_MOBILE, both FIXED_LINE and MOBILE would be present) and UNKNOWN. No types ...
[ "def", "supported_types_for_region", "(", "region_code", ")", ":", "if", "not", "_is_valid_region_code", "(", "region_code", ")", ":", "return", "set", "(", ")", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code", ".", "upper", "(", ...
Returns the types for a given region which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE (if numbers in this region could be classified as FIXED_LINE_OR_MOBILE, both FIXED_LINE and MOBILE would be present) and UNKNOWN. No types will be returned for invalid or unknown region codes...
[ "Returns", "the", "types", "for", "a", "given", "region", "which", "the", "library", "has", "metadata", "for", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L862-L874
220,830
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_number_type_geographical
def is_number_type_geographical(num_type, country_code): """Tests whether a phone number has a geographical association, as represented by its type and the country it belongs to. This version of isNumberGeographical exists since calculating the phone number type is expensive; if we have already done th...
python
def is_number_type_geographical(num_type, country_code): """Tests whether a phone number has a geographical association, as represented by its type and the country it belongs to. This version of isNumberGeographical exists since calculating the phone number type is expensive; if we have already done th...
[ "def", "is_number_type_geographical", "(", "num_type", ",", "country_code", ")", ":", "return", "(", "num_type", "==", "PhoneNumberType", ".", "FIXED_LINE", "or", "num_type", "==", "PhoneNumberType", ".", "FIXED_LINE_OR_MOBILE", "or", "(", "(", "country_code", "in",...
Tests whether a phone number has a geographical association, as represented by its type and the country it belongs to. This version of isNumberGeographical exists since calculating the phone number type is expensive; if we have already done this, we don't want to do it again.
[ "Tests", "whether", "a", "phone", "number", "has", "a", "geographical", "association", "as", "represented", "by", "its", "type", "and", "the", "country", "it", "belongs", "to", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L914-L925
220,831
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_number
def format_number(numobj, num_format): """Formats a phone number in the specified format using default rules. Note that this does not promise to produce a phone number that the user can dial from where they are - although we do format in either 'national' or 'international' format depending on what the...
python
def format_number(numobj, num_format): """Formats a phone number in the specified format using default rules. Note that this does not promise to produce a phone number that the user can dial from where they are - although we do format in either 'national' or 'international' format depending on what the...
[ "def", "format_number", "(", "numobj", ",", "num_format", ")", ":", "if", "numobj", ".", "national_number", "==", "0", "and", "numobj", ".", "raw_input", "is", "not", "None", ":", "# Unparseable numbers that kept their raw input just use that. This", "# is the only cas...
Formats a phone number in the specified format using default rules. Note that this does not promise to produce a phone number that the user can dial from where they are - although we do format in either 'national' or 'international' format depending on what the client asks for, we do not currently supp...
[ "Formats", "a", "phone", "number", "in", "the", "specified", "format", "using", "default", "rules", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L939-L992
220,832
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_by_pattern
def format_by_pattern(numobj, number_format, user_defined_formats): """Formats a phone number using client-defined formatting rules." Note that if the phone number has a country calling code of zero or an otherwise invalid country calling code, we cannot work out things like whether there should be a n...
python
def format_by_pattern(numobj, number_format, user_defined_formats): """Formats a phone number using client-defined formatting rules." Note that if the phone number has a country calling code of zero or an otherwise invalid country calling code, we cannot work out things like whether there should be a n...
[ "def", "format_by_pattern", "(", "numobj", ",", "number_format", ",", "user_defined_formats", ")", ":", "country_code", "=", "numobj", ".", "country_code", "nsn", "=", "national_significant_number", "(", "numobj", ")", "if", "not", "_has_valid_country_calling_code", "...
Formats a phone number using client-defined formatting rules." Note that if the phone number has a country calling code of zero or an otherwise invalid country calling code, we cannot work out things like whether there should be a national prefix applied, or how to format extensions, so we return the n...
[ "Formats", "a", "phone", "number", "using", "client", "-", "defined", "formatting", "rules", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L995-L1055
220,833
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_national_number_with_carrier_code
def format_national_number_with_carrier_code(numobj, carrier_code): """Format a number in national format for dialing using the specified carrier. The carrier-code will always be used regardless of whether the phone number already has a preferred domestic carrier code stored. If carrier_code contains a...
python
def format_national_number_with_carrier_code(numobj, carrier_code): """Format a number in national format for dialing using the specified carrier. The carrier-code will always be used regardless of whether the phone number already has a preferred domestic carrier code stored. If carrier_code contains a...
[ "def", "format_national_number_with_carrier_code", "(", "numobj", ",", "carrier_code", ")", ":", "country_code", "=", "numobj", ".", "country_code", "nsn", "=", "national_significant_number", "(", "numobj", ")", "if", "not", "_has_valid_country_calling_code", "(", "coun...
Format a number in national format for dialing using the specified carrier. The carrier-code will always be used regardless of whether the phone number already has a preferred domestic carrier code stored. If carrier_code contains an empty string, returns the number in national format without any carri...
[ "Format", "a", "number", "in", "national", "format", "for", "dialing", "using", "the", "specified", "carrier", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1058-L1095
220,834
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_national_number_with_preferred_carrier_code
def format_national_number_with_preferred_carrier_code(numobj, fallback_carrier_code): """Formats a phone number in national format for dialing using the carrier as specified in the preferred_domestic_carrier_code field of the PhoneNumber object passed in. If that is missing, use the fallback_carrier_co...
python
def format_national_number_with_preferred_carrier_code(numobj, fallback_carrier_code): """Formats a phone number in national format for dialing using the carrier as specified in the preferred_domestic_carrier_code field of the PhoneNumber object passed in. If that is missing, use the fallback_carrier_co...
[ "def", "format_national_number_with_preferred_carrier_code", "(", "numobj", ",", "fallback_carrier_code", ")", ":", "# Historically, we set this to an empty string when parsing with raw input", "# if none was found in the input string. However, this doesn't result in a", "# number we can dial. F...
Formats a phone number in national format for dialing using the carrier as specified in the preferred_domestic_carrier_code field of the PhoneNumber object passed in. If that is missing, use the fallback_carrier_code passed in instead. If there is no preferred_domestic_carrier_code, and the fallback_car...
[ "Formats", "a", "phone", "number", "in", "national", "format", "for", "dialing", "using", "the", "carrier", "as", "specified", "in", "the", "preferred_domestic_carrier_code", "field", "of", "the", "PhoneNumber", "object", "passed", "in", ".", "If", "that", "is",...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1098-L1129
220,835
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_number_for_mobile_dialing
def format_number_for_mobile_dialing(numobj, region_calling_from, with_formatting): """Returns a number formatted in such a way that it can be dialed from a mobile phone in a specific region. If the number cannot be reached from the region (e.g. some countries block toll-free numbers from being called...
python
def format_number_for_mobile_dialing(numobj, region_calling_from, with_formatting): """Returns a number formatted in such a way that it can be dialed from a mobile phone in a specific region. If the number cannot be reached from the region (e.g. some countries block toll-free numbers from being called...
[ "def", "format_number_for_mobile_dialing", "(", "numobj", ",", "region_calling_from", ",", "with_formatting", ")", ":", "country_calling_code", "=", "numobj", ".", "country_code", "if", "not", "_has_valid_country_calling_code", "(", "country_calling_code", ")", ":", "if",...
Returns a number formatted in such a way that it can be dialed from a mobile phone in a specific region. If the number cannot be reached from the region (e.g. some countries block toll-free numbers from being called outside of the country), the method returns an empty string. Arguments: numob...
[ "Returns", "a", "number", "formatted", "in", "such", "a", "way", "that", "it", "can", "be", "dialed", "from", "a", "mobile", "phone", "in", "a", "specific", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1132-L1248
220,836
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
format_in_original_format
def format_in_original_format(numobj, region_calling_from): """Format a number using the original format that the number was parsed from. The original format is embedded in the country_code_source field of the PhoneNumber object passed in. If such information is missing, the number will be formatted in...
python
def format_in_original_format(numobj, region_calling_from): """Format a number using the original format that the number was parsed from. The original format is embedded in the country_code_source field of the PhoneNumber object passed in. If such information is missing, the number will be formatted in...
[ "def", "format_in_original_format", "(", "numobj", ",", "region_calling_from", ")", ":", "if", "(", "numobj", ".", "raw_input", "is", "not", "None", "and", "not", "_has_formatting_pattern_for_number", "(", "numobj", ")", ")", ":", "# We check if we have the formatting...
Format a number using the original format that the number was parsed from. The original format is embedded in the country_code_source field of the PhoneNumber object passed in. If such information is missing, the number will be formatted into the NATIONAL format by default. When we don't have a forma...
[ "Format", "a", "number", "using", "the", "original", "format", "that", "the", "number", "was", "parsed", "from", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1333-L1371
220,837
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_raw_input_contains_national_prefix
def _raw_input_contains_national_prefix(raw_input, national_prefix, region_code): """Check if raw_input, which is assumed to be in the national format, has a national prefix. The national prefix is assumed to be in digits-only form.""" nnn = normalize_digits_only(raw_input) if nnn.startswith(nationa...
python
def _raw_input_contains_national_prefix(raw_input, national_prefix, region_code): """Check if raw_input, which is assumed to be in the national format, has a national prefix. The national prefix is assumed to be in digits-only form.""" nnn = normalize_digits_only(raw_input) if nnn.startswith(nationa...
[ "def", "_raw_input_contains_national_prefix", "(", "raw_input", ",", "national_prefix", ",", "region_code", ")", ":", "nnn", "=", "normalize_digits_only", "(", "raw_input", ")", "if", "nnn", ".", "startswith", "(", "national_prefix", ")", ":", "try", ":", "# Some ...
Check if raw_input, which is assumed to be in the national format, has a national prefix. The national prefix is assumed to be in digits-only form.
[ "Check", "if", "raw_input", "which", "is", "assumed", "to", "be", "in", "the", "national", "format", "has", "a", "national", "prefix", ".", "The", "national", "prefix", "is", "assumed", "to", "be", "in", "digits", "-", "only", "form", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1428-L1443
220,838
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
national_significant_number
def national_significant_number(numobj): """Gets the national significant number of a phone number. Note that a national significant number doesn't contain a national prefix or any formatting. Arguments: numobj -- The PhoneNumber object for which the national significant number is ne...
python
def national_significant_number(numobj): """Gets the national significant number of a phone number. Note that a national significant number doesn't contain a national prefix or any formatting. Arguments: numobj -- The PhoneNumber object for which the national significant number is ne...
[ "def", "national_significant_number", "(", "numobj", ")", ":", "# If leading zero(s) have been set, we prefix this now. Note this is not a", "# national prefix.", "national_number", "=", "U_EMPTY_STRING", "if", "numobj", ".", "italian_leading_zero", ":", "num_zeros", "=", "numobj...
Gets the national significant number of a phone number. Note that a national significant number doesn't contain a national prefix or any formatting. Arguments: numobj -- The PhoneNumber object for which the national significant number is needed. Returns the national significant numb...
[ "Gets", "the", "national", "significant", "number", "of", "a", "phone", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1571-L1594
220,839
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_prefix_number_with_country_calling_code
def _prefix_number_with_country_calling_code(country_code, num_format, formatted_number): """A helper function that is used by format_number and format_by_pattern.""" if num_format == PhoneNumberFormat.E164: return _PLUS_SIGN + unicod(country_code) + formatted_number elif num_format == PhoneNumberFo...
python
def _prefix_number_with_country_calling_code(country_code, num_format, formatted_number): """A helper function that is used by format_number and format_by_pattern.""" if num_format == PhoneNumberFormat.E164: return _PLUS_SIGN + unicod(country_code) + formatted_number elif num_format == PhoneNumberFo...
[ "def", "_prefix_number_with_country_calling_code", "(", "country_code", ",", "num_format", ",", "formatted_number", ")", ":", "if", "num_format", "==", "PhoneNumberFormat", ".", "E164", ":", "return", "_PLUS_SIGN", "+", "unicod", "(", "country_code", ")", "+", "form...
A helper function that is used by format_number and format_by_pattern.
[ "A", "helper", "function", "that", "is", "used", "by", "format_number", "and", "format_by_pattern", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1597-L1606
220,840
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_format_nsn
def _format_nsn(number, metadata, num_format, carrier_code=None): """Format a national number.""" # Note in some regions, the national number can be written in two # completely different ways depending on whether it forms part of the # NATIONAL format or INTERNATIONAL format. The num_format parameter he...
python
def _format_nsn(number, metadata, num_format, carrier_code=None): """Format a national number.""" # Note in some regions, the national number can be written in two # completely different ways depending on whether it forms part of the # NATIONAL format or INTERNATIONAL format. The num_format parameter he...
[ "def", "_format_nsn", "(", "number", ",", "metadata", ",", "num_format", ",", "carrier_code", "=", "None", ")", ":", "# Note in some regions, the national number can be written in two", "# completely different ways depending on whether it forms part of the", "# NATIONAL format or INT...
Format a national number.
[ "Format", "a", "national", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1609-L1631
220,841
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
invalid_example_number
def invalid_example_number(region_code): """Gets an invalid number for the specified region. This is useful for unit-testing purposes, where you want to test what will happen with an invalid number. Note that the number that is returned will always be able to be parsed and will have the correct cou...
python
def invalid_example_number(region_code): """Gets an invalid number for the specified region. This is useful for unit-testing purposes, where you want to test what will happen with an invalid number. Note that the number that is returned will always be able to be parsed and will have the correct cou...
[ "def", "invalid_example_number", "(", "region_code", ")", ":", "if", "not", "_is_valid_region_code", "(", "region_code", ")", ":", "return", "None", "# We start off with a valid fixed-line number since every country", "# supports this. Alternatively we could start with a different nu...
Gets an invalid number for the specified region. This is useful for unit-testing purposes, where you want to test what will happen with an invalid number. Note that the number that is returned will always be able to be parsed and will have the correct country code. It may also be a valid *short* number...
[ "Gets", "an", "invalid", "number", "for", "the", "specified", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1709-L1769
220,842
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
example_number_for_type
def example_number_for_type(region_code, num_type): """Gets a valid number for the specified region and number type. If None is given as the region_code, then the returned number object may belong to any country. Arguments: region_code -- The region for which an example number is needed, or None. ...
python
def example_number_for_type(region_code, num_type): """Gets a valid number for the specified region and number type. If None is given as the region_code, then the returned number object may belong to any country. Arguments: region_code -- The region for which an example number is needed, or None. ...
[ "def", "example_number_for_type", "(", "region_code", ",", "num_type", ")", ":", "if", "region_code", "is", "None", ":", "return", "_example_number_anywhere_for_type", "(", "num_type", ")", "# Check the region code is valid.", "if", "not", "_is_valid_region_code", "(", ...
Gets a valid number for the specified region and number type. If None is given as the region_code, then the returned number object may belong to any country. Arguments: region_code -- The region for which an example number is needed, or None. num_type -- The type of number that is needed. Ret...
[ "Gets", "a", "valid", "number", "for", "the", "specified", "region", "and", "number", "type", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1772-L1799
220,843
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
example_number_for_non_geo_entity
def example_number_for_non_geo_entity(country_calling_code): """Gets a valid number for the specified country calling code for a non-geographical entity. Arguments: country_calling_code -- The country calling code for a non-geographical entity. Returns a valid number for the non-geographical entity. R...
python
def example_number_for_non_geo_entity(country_calling_code): """Gets a valid number for the specified country calling code for a non-geographical entity. Arguments: country_calling_code -- The country calling code for a non-geographical entity. Returns a valid number for the non-geographical entity. R...
[ "def", "example_number_for_non_geo_entity", "(", "country_calling_code", ")", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_nongeo_region", "(", "country_calling_code", ",", "None", ")", "if", "metadata", "is", "not", "None", ":", "# For geographical entities,...
Gets a valid number for the specified country calling code for a non-geographical entity. Arguments: country_calling_code -- The country calling code for a non-geographical entity. Returns a valid number for the non-geographical entity. Returns None when the metadata does not contain such information,...
[ "Gets", "a", "valid", "number", "for", "the", "specified", "country", "calling", "code", "for", "a", "non", "-", "geographical", "entity", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1830-L1853
220,844
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_maybe_append_formatted_extension
def _maybe_append_formatted_extension(numobj, metadata, num_format, number): """Appends the formatted extension of a phone number to formatted number, if the phone number had an extension specified. """ if numobj.extension: if num_format == PhoneNumberFormat.RFC3966: return number + ...
python
def _maybe_append_formatted_extension(numobj, metadata, num_format, number): """Appends the formatted extension of a phone number to formatted number, if the phone number had an extension specified. """ if numobj.extension: if num_format == PhoneNumberFormat.RFC3966: return number + ...
[ "def", "_maybe_append_formatted_extension", "(", "numobj", ",", "metadata", ",", "num_format", ",", "number", ")", ":", "if", "numobj", ".", "extension", ":", "if", "num_format", "==", "PhoneNumberFormat", ".", "RFC3966", ":", "return", "number", "+", "_RFC3966_...
Appends the formatted extension of a phone number to formatted number, if the phone number had an extension specified.
[ "Appends", "the", "formatted", "extension", "of", "a", "phone", "number", "to", "formatted", "number", "if", "the", "phone", "number", "had", "an", "extension", "specified", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1856-L1868
220,845
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_number_desc_by_type
def _number_desc_by_type(metadata, num_type): """Return the PhoneNumberDesc of the metadata for the given number type""" if num_type == PhoneNumberType.PREMIUM_RATE: return metadata.premium_rate elif num_type == PhoneNumberType.TOLL_FREE: return metadata.toll_free elif num_type == PhoneN...
python
def _number_desc_by_type(metadata, num_type): """Return the PhoneNumberDesc of the metadata for the given number type""" if num_type == PhoneNumberType.PREMIUM_RATE: return metadata.premium_rate elif num_type == PhoneNumberType.TOLL_FREE: return metadata.toll_free elif num_type == PhoneN...
[ "def", "_number_desc_by_type", "(", "metadata", ",", "num_type", ")", ":", "if", "num_type", "==", "PhoneNumberType", ".", "PREMIUM_RATE", ":", "return", "metadata", ".", "premium_rate", "elif", "num_type", "==", "PhoneNumberType", ".", "TOLL_FREE", ":", "return",...
Return the PhoneNumberDesc of the metadata for the given number type
[ "Return", "the", "PhoneNumberDesc", "of", "the", "metadata", "for", "the", "given", "number", "type" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1871-L1895
220,846
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
number_type
def number_type(numobj): """Gets the type of a valid phone number. Arguments: numobj -- The PhoneNumber object that we want to know the type of. Returns the type of the phone number, as a PhoneNumberType value; returns PhoneNumberType.UNKNOWN if it is invalid. """ region_code = region_code...
python
def number_type(numobj): """Gets the type of a valid phone number. Arguments: numobj -- The PhoneNumber object that we want to know the type of. Returns the type of the phone number, as a PhoneNumberType value; returns PhoneNumberType.UNKNOWN if it is invalid. """ region_code = region_code...
[ "def", "number_type", "(", "numobj", ")", ":", "region_code", "=", "region_code_for_number", "(", "numobj", ")", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region_or_calling_code", "(", "numobj", ".", "country_code", ",", "region_code", ")", "if", "metadat...
Gets the type of a valid phone number. Arguments: numobj -- The PhoneNumber object that we want to know the type of. Returns the type of the phone number, as a PhoneNumberType value; returns PhoneNumberType.UNKNOWN if it is invalid.
[ "Gets", "the", "type", "of", "a", "valid", "phone", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1898-L1912
220,847
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_number_type_helper
def _number_type_helper(national_number, metadata): """Return the type of the given number against the metadata""" if not _is_number_matching_desc(national_number, metadata.general_desc): return PhoneNumberType.UNKNOWN if _is_number_matching_desc(national_number, metadata.premium_rate): retu...
python
def _number_type_helper(national_number, metadata): """Return the type of the given number against the metadata""" if not _is_number_matching_desc(national_number, metadata.general_desc): return PhoneNumberType.UNKNOWN if _is_number_matching_desc(national_number, metadata.premium_rate): retu...
[ "def", "_number_type_helper", "(", "national_number", ",", "metadata", ")", ":", "if", "not", "_is_number_matching_desc", "(", "national_number", ",", "metadata", ".", "general_desc", ")", ":", "return", "PhoneNumberType", ".", "UNKNOWN", "if", "_is_number_matching_de...
Return the type of the given number against the metadata
[ "Return", "the", "type", "of", "the", "given", "number", "against", "the", "metadata" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1915-L1948
220,848
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_number_matching_desc
def _is_number_matching_desc(national_number, number_desc): """Determine if the number matches the given PhoneNumberDesc""" # Check if any possible number lengths are present; if so, we use them to avoid checking the # validation pattern if they don't match. If they are absent, this means they match the gen...
python
def _is_number_matching_desc(national_number, number_desc): """Determine if the number matches the given PhoneNumberDesc""" # Check if any possible number lengths are present; if so, we use them to avoid checking the # validation pattern if they don't match. If they are absent, this means they match the gen...
[ "def", "_is_number_matching_desc", "(", "national_number", ",", "number_desc", ")", ":", "# Check if any possible number lengths are present; if so, we use them to avoid checking the", "# validation pattern if they don't match. If they are absent, this means they match the general", "# descripti...
Determine if the number matches the given PhoneNumberDesc
[ "Determine", "if", "the", "number", "matches", "the", "given", "PhoneNumberDesc" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1951-L1962
220,849
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_valid_number_for_region
def is_valid_number_for_region(numobj, region_code): """Tests whether a phone number is valid for a certain region. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself. If the country calling code is not the same as the country calling ...
python
def is_valid_number_for_region(numobj, region_code): """Tests whether a phone number is valid for a certain region. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself. If the country calling code is not the same as the country calling ...
[ "def", "is_valid_number_for_region", "(", "numobj", ",", "region_code", ")", ":", "country_code", "=", "numobj", ".", "country_code", "if", "region_code", "is", "None", ":", "return", "False", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region_or_calling_code...
Tests whether a phone number is valid for a certain region. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself. If the country calling code is not the same as the country calling code for the region, this immediately exits with false. ...
[ "Tests", "whether", "a", "phone", "number", "is", "valid", "for", "a", "certain", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L1986-L2019
220,850
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
region_code_for_number
def region_code_for_number(numobj): """Returns the region where a phone number is from. This could be used for geocoding at the region level. Only guarantees correct results for valid, full numbers (not short-codes, or invalid numbers). Arguments: numobj -- The phone number object whose origin...
python
def region_code_for_number(numobj): """Returns the region where a phone number is from. This could be used for geocoding at the region level. Only guarantees correct results for valid, full numbers (not short-codes, or invalid numbers). Arguments: numobj -- The phone number object whose origin...
[ "def", "region_code_for_number", "(", "numobj", ")", ":", "country_code", "=", "numobj", ".", "country_code", "regions", "=", "COUNTRY_CODE_TO_REGION_CODE", ".", "get", "(", "country_code", ",", "None", ")", "if", "regions", "is", "None", ":", "return", "None", ...
Returns the region where a phone number is from. This could be used for geocoding at the region level. Only guarantees correct results for valid, full numbers (not short-codes, or invalid numbers). Arguments: numobj -- The phone number object whose origin we want to know Returns the region wh...
[ "Returns", "the", "region", "where", "a", "phone", "number", "is", "from", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2022-L2044
220,851
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_region_code_for_number_from_list
def _region_code_for_number_from_list(numobj, regions): """Find the region in a list that matches a number""" national_number = national_significant_number(numobj) for region_code in regions: # If leading_digits is present, use this. Otherwise, do full # validation. # Metadata cannot...
python
def _region_code_for_number_from_list(numobj, regions): """Find the region in a list that matches a number""" national_number = national_significant_number(numobj) for region_code in regions: # If leading_digits is present, use this. Otherwise, do full # validation. # Metadata cannot...
[ "def", "_region_code_for_number_from_list", "(", "numobj", ",", "regions", ")", ":", "national_number", "=", "national_significant_number", "(", "numobj", ")", "for", "region_code", "in", "regions", ":", "# If leading_digits is present, use this. Otherwise, do full", "# valid...
Find the region in a list that matches a number
[ "Find", "the", "region", "in", "a", "list", "that", "matches", "a", "number" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2047-L2065
220,852
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
country_code_for_valid_region
def country_code_for_valid_region(region_code): """Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand. Assumes the region is already valid. Arguments: region_code -- The region that we want to get the country calling ...
python
def country_code_for_valid_region(region_code): """Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand. Assumes the region is already valid. Arguments: region_code -- The region that we want to get the country calling ...
[ "def", "country_code_for_valid_region", "(", "region_code", ")", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code", ".", "upper", "(", ")", ",", "None", ")", "if", "metadata", "is", "None", ":", "raise", "Exception", "(", "\...
Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand. Assumes the region is already valid. Arguments: region_code -- The region that we want to get the country calling code for. Returns the country calling code for the...
[ "Returns", "the", "country", "calling", "code", "for", "a", "specific", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2116-L2130
220,853
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
ndd_prefix_for_region
def ndd_prefix_for_region(region_code, strip_non_digits): """Returns the national dialling prefix for a specific region. For example, this would be 1 for the United States, and 0 for New Zealand. Set strip_non_digits to True to strip symbols like "~" (which indicates a wait for a dialling tone) from th...
python
def ndd_prefix_for_region(region_code, strip_non_digits): """Returns the national dialling prefix for a specific region. For example, this would be 1 for the United States, and 0 for New Zealand. Set strip_non_digits to True to strip symbols like "~" (which indicates a wait for a dialling tone) from th...
[ "def", "ndd_prefix_for_region", "(", "region_code", ",", "strip_non_digits", ")", ":", "if", "region_code", "is", "None", ":", "return", "None", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code", ".", "upper", "(", ")", ",", "None"...
Returns the national dialling prefix for a specific region. For example, this would be 1 for the United States, and 0 for New Zealand. Set strip_non_digits to True to strip symbols like "~" (which indicates a wait for a dialling tone) from the prefix returned. If no national prefix is present, we retur...
[ "Returns", "the", "national", "dialling", "prefix", "for", "a", "specific", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2133-L2165
220,854
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_possible_number
def is_possible_number(numobj): """Convenience wrapper around is_possible_number_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the number could be a possible...
python
def is_possible_number(numobj): """Convenience wrapper around is_possible_number_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the number could be a possible...
[ "def", "is_possible_number", "(", "numobj", ")", ":", "result", "=", "is_possible_number_with_reason", "(", "numobj", ")", "return", "(", "result", "==", "ValidationResult", ".", "IS_POSSIBLE", "or", "result", "==", "ValidationResult", ".", "IS_POSSIBLE_LOCAL_ONLY", ...
Convenience wrapper around is_possible_number_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the number could be a possible local number (with a country code,...
[ "Convenience", "wrapper", "around", "is_possible_number_with_reason", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2197-L2216
220,855
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_possible_number_for_type
def is_possible_number_for_type(numobj, numtype): """Convenience wrapper around is_possible_number_for_type_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the...
python
def is_possible_number_for_type(numobj, numtype): """Convenience wrapper around is_possible_number_for_type_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the...
[ "def", "is_possible_number_for_type", "(", "numobj", ",", "numtype", ")", ":", "result", "=", "is_possible_number_for_type_with_reason", "(", "numobj", ",", "numtype", ")", "return", "(", "result", "==", "ValidationResult", ".", "IS_POSSIBLE", "or", "result", "==", ...
Convenience wrapper around is_possible_number_for_type_with_reason. Instead of returning the reason for failure, this method returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the number could be a possible local number (with a coun...
[ "Convenience", "wrapper", "around", "is_possible_number_for_type_with_reason", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2219-L2239
220,856
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_possible_number_for_type_with_reason
def is_possible_number_for_type_with_reason(numobj, numtype): """Check whether a phone number is a possible number of a particular type. For types that don't exist in a particular region, this will return a result that isn't so useful; it is recommended that you use supported_types_for_region or suppor...
python
def is_possible_number_for_type_with_reason(numobj, numtype): """Check whether a phone number is a possible number of a particular type. For types that don't exist in a particular region, this will return a result that isn't so useful; it is recommended that you use supported_types_for_region or suppor...
[ "def", "is_possible_number_for_type_with_reason", "(", "numobj", ",", "numtype", ")", ":", "national_number", "=", "national_significant_number", "(", "numobj", ")", "country_code", "=", "numobj", ".", "country_code", "# Note: For regions that share a country calling code, like...
Check whether a phone number is a possible number of a particular type. For types that don't exist in a particular region, this will return a result that isn't so useful; it is recommended that you use supported_types_for_region or supported_types_for_non_geo_entity respectively before calling this met...
[ "Check", "whether", "a", "phone", "number", "is", "a", "possible", "number", "of", "a", "particular", "type", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2318-L2365
220,857
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
truncate_too_long_number
def truncate_too_long_number(numobj): """Truncate a number object that is too long. Attempts to extract a valid number from a phone number that is too long to be valid, and resets the PhoneNumber object passed in to that valid version. If no valid number could be extracted, the PhoneNumber object p...
python
def truncate_too_long_number(numobj): """Truncate a number object that is too long. Attempts to extract a valid number from a phone number that is too long to be valid, and resets the PhoneNumber object passed in to that valid version. If no valid number could be extracted, the PhoneNumber object p...
[ "def", "truncate_too_long_number", "(", "numobj", ")", ":", "if", "is_valid_number", "(", "numobj", ")", ":", "return", "True", "numobj_copy", "=", "PhoneNumber", "(", ")", "numobj_copy", ".", "merge_from", "(", "numobj", ")", "national_number", "=", "numobj", ...
Truncate a number object that is too long. Attempts to extract a valid number from a phone number that is too long to be valid, and resets the PhoneNumber object passed in to that valid version. If no valid number could be extracted, the PhoneNumber object passed in will not be modified. Arguments...
[ "Truncate", "a", "number", "object", "that", "is", "too", "long", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2399-L2429
220,858
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_extract_country_code
def _extract_country_code(number): """Extracts country calling code from number. Returns a 2-tuple of (country_calling_code, rest_of_number). It assumes that the leading plus sign or IDD has already been removed. Returns (0, number) if number doesn't start with a valid country calling code. """ ...
python
def _extract_country_code(number): """Extracts country calling code from number. Returns a 2-tuple of (country_calling_code, rest_of_number). It assumes that the leading plus sign or IDD has already been removed. Returns (0, number) if number doesn't start with a valid country calling code. """ ...
[ "def", "_extract_country_code", "(", "number", ")", ":", "if", "len", "(", "number", ")", "==", "0", "or", "number", "[", "0", "]", "==", "U_ZERO", ":", "# Country codes do not begin with a '0'.", "return", "(", "0", ",", "number", ")", "for", "ii", "in", ...
Extracts country calling code from number. Returns a 2-tuple of (country_calling_code, rest_of_number). It assumes that the leading plus sign or IDD has already been removed. Returns (0, number) if number doesn't start with a valid country calling code.
[ "Extracts", "country", "calling", "code", "from", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2432-L2450
220,859
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_maybe_extract_country_code
def _maybe_extract_country_code(number, metadata, keep_raw_input, numobj): """Tries to extract a country calling code from a number. This method will return zero if no country calling code is considered to be present. Country calling codes are extracted in the following ways: - by stripping the inter...
python
def _maybe_extract_country_code(number, metadata, keep_raw_input, numobj): """Tries to extract a country calling code from a number. This method will return zero if no country calling code is considered to be present. Country calling codes are extracted in the following ways: - by stripping the inter...
[ "def", "_maybe_extract_country_code", "(", "number", ",", "metadata", ",", "keep_raw_input", ",", "numobj", ")", ":", "if", "len", "(", "number", ")", "==", "0", ":", "return", "(", "0", ",", "U_EMPTY_STRING", ")", "full_number", "=", "number", "# Set the de...
Tries to extract a country calling code from a number. This method will return zero if no country calling code is considered to be present. Country calling codes are extracted in the following ways: - by stripping the international dialing prefix of the region the person is dialing from, if this i...
[ "Tries", "to", "extract", "a", "country", "calling", "code", "from", "a", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2453-L2549
220,860
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_parse_prefix_as_idd
def _parse_prefix_as_idd(idd_pattern, number): """Strips the IDD from the start of the number if present. Helper function used by _maybe_strip_i18n_prefix_and_normalize(). Returns a 2-tuple: - Boolean indicating if IDD was stripped - Number with IDD stripped """ match = idd_pattern.mat...
python
def _parse_prefix_as_idd(idd_pattern, number): """Strips the IDD from the start of the number if present. Helper function used by _maybe_strip_i18n_prefix_and_normalize(). Returns a 2-tuple: - Boolean indicating if IDD was stripped - Number with IDD stripped """ match = idd_pattern.mat...
[ "def", "_parse_prefix_as_idd", "(", "idd_pattern", ",", "number", ")", ":", "match", "=", "idd_pattern", ".", "match", "(", "number", ")", "if", "match", ":", "match_end", "=", "match", ".", "end", "(", ")", "# Only strip this if the first digit after the match is...
Strips the IDD from the start of the number if present. Helper function used by _maybe_strip_i18n_prefix_and_normalize(). Returns a 2-tuple: - Boolean indicating if IDD was stripped - Number with IDD stripped
[ "Strips", "the", "IDD", "from", "the", "start", "of", "the", "number", "if", "present", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2552-L2572
220,861
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_maybe_strip_extension
def _maybe_strip_extension(number): """Strip extension from the end of a number string. Strips any extension (as in, the part of the number dialled after the call is connected, usually indicated with extn, ext, x or similar) from the end of the number, and returns it. Arguments: number -- the ...
python
def _maybe_strip_extension(number): """Strip extension from the end of a number string. Strips any extension (as in, the part of the number dialled after the call is connected, usually indicated with extn, ext, x or similar) from the end of the number, and returns it. Arguments: number -- the ...
[ "def", "_maybe_strip_extension", "(", "number", ")", ":", "match", "=", "_EXTN_PATTERN", ".", "search", "(", "number", ")", "# If we find a potential extension, and the number preceding this is a", "# viable number, we assume it is an extension.", "if", "match", "and", "_is_via...
Strip extension from the end of a number string. Strips any extension (as in, the part of the number dialled after the call is connected, usually indicated with extn, ext, x or similar) from the end of the number, and returns it. Arguments: number -- the non-normalized telephone number that we wis...
[ "Strip", "extension", "from", "the", "end", "of", "a", "number", "string", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2676-L2701
220,862
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_check_region_for_parsing
def _check_region_for_parsing(number, default_region): """Checks to see that the region code used is valid, or if it is not valid, that the number to parse starts with a + symbol so that we can attempt to infer the region from the number. Returns False if it cannot use the region provided and the regio...
python
def _check_region_for_parsing(number, default_region): """Checks to see that the region code used is valid, or if it is not valid, that the number to parse starts with a + symbol so that we can attempt to infer the region from the number. Returns False if it cannot use the region provided and the regio...
[ "def", "_check_region_for_parsing", "(", "number", ",", "default_region", ")", ":", "if", "not", "_is_valid_region_code", "(", "default_region", ")", ":", "# If the number is None or empty, we can't infer the region.", "if", "number", "is", "None", "or", "len", "(", "nu...
Checks to see that the region code used is valid, or if it is not valid, that the number to parse starts with a + symbol so that we can attempt to infer the region from the number. Returns False if it cannot use the region provided and the region cannot be inferred.
[ "Checks", "to", "see", "that", "the", "region", "code", "used", "is", "valid", "or", "if", "it", "is", "not", "valid", "that", "the", "number", "to", "parse", "starts", "with", "a", "+", "symbol", "so", "that", "we", "can", "attempt", "to", "infer", ...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2704-L2717
220,863
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_set_italian_leading_zeros_for_phone_number
def _set_italian_leading_zeros_for_phone_number(national_number, numobj): """A helper function to set the values related to leading zeros in a PhoneNumber.""" if len(national_number) > 1 and national_number[0] == U_ZERO: numobj.italian_leading_zero = True number_of_leading_zeros = 1 ...
python
def _set_italian_leading_zeros_for_phone_number(national_number, numobj): """A helper function to set the values related to leading zeros in a PhoneNumber.""" if len(national_number) > 1 and national_number[0] == U_ZERO: numobj.italian_leading_zero = True number_of_leading_zeros = 1 ...
[ "def", "_set_italian_leading_zeros_for_phone_number", "(", "national_number", ",", "numobj", ")", ":", "if", "len", "(", "national_number", ")", ">", "1", "and", "national_number", "[", "0", "]", "==", "U_ZERO", ":", "numobj", ".", "italian_leading_zero", "=", "...
A helper function to set the values related to leading zeros in a PhoneNumber.
[ "A", "helper", "function", "to", "set", "the", "values", "related", "to", "leading", "zeros", "in", "a", "PhoneNumber", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2720-L2732
220,864
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
parse
def parse(number, region=None, keep_raw_input=False, numobj=None, _check_region=True): """Parse a string and return a corresponding PhoneNumber object. The method is quite lenient and looks for a number in the input text (raw input) and does not check whether the string is definitely only a p...
python
def parse(number, region=None, keep_raw_input=False, numobj=None, _check_region=True): """Parse a string and return a corresponding PhoneNumber object. The method is quite lenient and looks for a number in the input text (raw input) and does not check whether the string is definitely only a p...
[ "def", "parse", "(", "number", ",", "region", "=", "None", ",", "keep_raw_input", "=", "False", ",", "numobj", "=", "None", ",", "_check_region", "=", "True", ")", ":", "if", "numobj", "is", "None", ":", "numobj", "=", "PhoneNumber", "(", ")", "if", ...
Parse a string and return a corresponding PhoneNumber object. The method is quite lenient and looks for a number in the input text (raw input) and does not check whether the string is definitely only a phone number. To do this, it ignores punctuation and white-space, as well as any text before the numb...
[ "Parse", "a", "string", "and", "return", "a", "corresponding", "PhoneNumber", "object", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2735-L2893
220,865
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_build_national_number_for_parsing
def _build_national_number_for_parsing(number): """Converts number to a form that we can parse and return it if it is written in RFC3966; otherwise extract a possible number out of it and return it.""" index_of_phone_context = number.find(_RFC3966_PHONE_CONTEXT) if index_of_phone_context >= 0: p...
python
def _build_national_number_for_parsing(number): """Converts number to a form that we can parse and return it if it is written in RFC3966; otherwise extract a possible number out of it and return it.""" index_of_phone_context = number.find(_RFC3966_PHONE_CONTEXT) if index_of_phone_context >= 0: p...
[ "def", "_build_national_number_for_parsing", "(", "number", ")", ":", "index_of_phone_context", "=", "number", ".", "find", "(", "_RFC3966_PHONE_CONTEXT", ")", "if", "index_of_phone_context", ">=", "0", ":", "phone_context_start", "=", "index_of_phone_context", "+", "le...
Converts number to a form that we can parse and return it if it is written in RFC3966; otherwise extract a possible number out of it and return it.
[ "Converts", "number", "to", "a", "form", "that", "we", "can", "parse", "and", "return", "it", "if", "it", "is", "written", "in", "RFC3966", ";", "otherwise", "extract", "a", "possible", "number", "out", "of", "it", "and", "return", "it", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2896-L2941
220,866
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_copy_core_fields_only
def _copy_core_fields_only(inobj): """Returns a new phone number containing only the fields needed to uniquely identify a phone number, rather than any fields that capture the context in which the phone number was created. """ numobj = PhoneNumber() numobj.country_code = inobj.country_code n...
python
def _copy_core_fields_only(inobj): """Returns a new phone number containing only the fields needed to uniquely identify a phone number, rather than any fields that capture the context in which the phone number was created. """ numobj = PhoneNumber() numobj.country_code = inobj.country_code n...
[ "def", "_copy_core_fields_only", "(", "inobj", ")", ":", "numobj", "=", "PhoneNumber", "(", ")", "numobj", ".", "country_code", "=", "inobj", ".", "country_code", "numobj", ".", "national_number", "=", "inobj", ".", "national_number", "if", "inobj", ".", "exte...
Returns a new phone number containing only the fields needed to uniquely identify a phone number, rather than any fields that capture the context in which the phone number was created.
[ "Returns", "a", "new", "phone", "number", "containing", "only", "the", "fields", "needed", "to", "uniquely", "identify", "a", "phone", "number", "rather", "than", "any", "fields", "that", "capture", "the", "context", "in", "which", "the", "phone", "number", ...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2944-L2961
220,867
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_number_match_OO
def _is_number_match_OO(numobj1_in, numobj2_in): """Takes two phone number objects and compares them for equality.""" # We only care about the fields that uniquely define a number, so we copy these across explicitly. numobj1 = _copy_core_fields_only(numobj1_in) numobj2 = _copy_core_fields_only(numobj2_i...
python
def _is_number_match_OO(numobj1_in, numobj2_in): """Takes two phone number objects and compares them for equality.""" # We only care about the fields that uniquely define a number, so we copy these across explicitly. numobj1 = _copy_core_fields_only(numobj1_in) numobj2 = _copy_core_fields_only(numobj2_i...
[ "def", "_is_number_match_OO", "(", "numobj1_in", ",", "numobj2_in", ")", ":", "# We only care about the fields that uniquely define a number, so we copy these across explicitly.", "numobj1", "=", "_copy_core_fields_only", "(", "numobj1_in", ")", "numobj2", "=", "_copy_core_fields_o...
Takes two phone number objects and compares them for equality.
[ "Takes", "two", "phone", "number", "objects", "and", "compares", "them", "for", "equality", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L2964-L3001
220,868
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_national_number_suffix_of_other
def _is_national_number_suffix_of_other(numobj1, numobj2): """Returns true when one national number is the suffix of the other or both are the same. """ nn1 = str(numobj1.national_number) nn2 = str(numobj2.national_number) # Note that endswith returns True if the numbers are equal. return nn...
python
def _is_national_number_suffix_of_other(numobj1, numobj2): """Returns true when one national number is the suffix of the other or both are the same. """ nn1 = str(numobj1.national_number) nn2 = str(numobj2.national_number) # Note that endswith returns True if the numbers are equal. return nn...
[ "def", "_is_national_number_suffix_of_other", "(", "numobj1", ",", "numobj2", ")", ":", "nn1", "=", "str", "(", "numobj1", ".", "national_number", ")", "nn2", "=", "str", "(", "numobj2", ".", "national_number", ")", "# Note that endswith returns True if the numbers ar...
Returns true when one national number is the suffix of the other or both are the same.
[ "Returns", "true", "when", "one", "national", "number", "is", "the", "suffix", "of", "the", "other", "or", "both", "are", "the", "same", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3004-L3011
220,869
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_number_match_SS
def _is_number_match_SS(number1, number2): """Takes two phone numbers as strings and compares them for equality. This is a convenience wrapper for _is_number_match_OO/_is_number_match_OS. No default region is known. """ try: numobj1 = parse(number1, UNKNOWN_REGION) return _is_number...
python
def _is_number_match_SS(number1, number2): """Takes two phone numbers as strings and compares them for equality. This is a convenience wrapper for _is_number_match_OO/_is_number_match_OS. No default region is known. """ try: numobj1 = parse(number1, UNKNOWN_REGION) return _is_number...
[ "def", "_is_number_match_SS", "(", "number1", ",", "number2", ")", ":", "try", ":", "numobj1", "=", "parse", "(", "number1", ",", "UNKNOWN_REGION", ")", "return", "_is_number_match_OS", "(", "numobj1", ",", "number2", ")", "except", "NumberParseException", ":", ...
Takes two phone numbers as strings and compares them for equality. This is a convenience wrapper for _is_number_match_OO/_is_number_match_OS. No default region is known.
[ "Takes", "two", "phone", "numbers", "as", "strings", "and", "compares", "them", "for", "equality", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3014-L3043
220,870
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
_is_number_match_OS
def _is_number_match_OS(numobj1, number2): """Wrapper variant of _is_number_match_OO that copes with one PhoneNumber object and one string.""" # First see if the second number has an implicit country calling code, by # attempting to parse it. try: numobj2 = parse(number2, UNKNOWN_REGION) ...
python
def _is_number_match_OS(numobj1, number2): """Wrapper variant of _is_number_match_OO that copes with one PhoneNumber object and one string.""" # First see if the second number has an implicit country calling code, by # attempting to parse it. try: numobj2 = parse(number2, UNKNOWN_REGION) ...
[ "def", "_is_number_match_OS", "(", "numobj1", ",", "number2", ")", ":", "# First see if the second number has an implicit country calling code, by", "# attempting to parse it.", "try", ":", "numobj2", "=", "parse", "(", "number2", ",", "UNKNOWN_REGION", ")", "return", "_is_...
Wrapper variant of _is_number_match_OO that copes with one PhoneNumber object and one string.
[ "Wrapper", "variant", "of", "_is_number_match_OO", "that", "copes", "with", "one", "PhoneNumber", "object", "and", "one", "string", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3046-L3081
220,871
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_number_match
def is_number_match(num1, num2): """Takes two phone numbers and compares them for equality. For example, the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH. The numbers +1 345 657 1234 and 345 657 are a NO_MATCH. Arguments num1 -- First number object or string to compare. Can contain f...
python
def is_number_match(num1, num2): """Takes two phone numbers and compares them for equality. For example, the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH. The numbers +1 345 657 1234 and 345 657 are a NO_MATCH. Arguments num1 -- First number object or string to compare. Can contain f...
[ "def", "is_number_match", "(", "num1", ",", "num2", ")", ":", "if", "isinstance", "(", "num1", ",", "PhoneNumber", ")", "and", "isinstance", "(", "num2", ",", "PhoneNumber", ")", ":", "return", "_is_number_match_OO", "(", "num1", ",", "num2", ")", "elif", ...
Takes two phone numbers and compares them for equality. For example, the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH. The numbers +1 345 657 1234 and 345 657 are a NO_MATCH. Arguments num1 -- First number object or string to compare. Can contain formatting, and can have co...
[ "Takes", "two", "phone", "numbers", "and", "compares", "them", "for", "equality", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3084-L3114
220,872
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
can_be_internationally_dialled
def can_be_internationally_dialled(numobj): """Returns True if the number can only be dialled from outside the region, or unknown. If the number can only be dialled from within the region as well, returns False. Does not check the number is a valid number. Note that, at the moment, this method does...
python
def can_be_internationally_dialled(numobj): """Returns True if the number can only be dialled from outside the region, or unknown. If the number can only be dialled from within the region as well, returns False. Does not check the number is a valid number. Note that, at the moment, this method does...
[ "def", "can_be_internationally_dialled", "(", "numobj", ")", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code_for_number", "(", "numobj", ")", ",", "None", ")", "if", "metadata", "is", "None", ":", "# Note numbers belonging to non-g...
Returns True if the number can only be dialled from outside the region, or unknown. If the number can only be dialled from within the region as well, returns False. Does not check the number is a valid number. Note that, at the moment, this method does not handle short numbers (which are currently ...
[ "Returns", "True", "if", "the", "number", "can", "only", "be", "dialled", "from", "outside", "the", "region", "or", "unknown", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3117-L3137
220,873
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumberutil.py
is_mobile_number_portable_region
def is_mobile_number_portable_region(region_code): """Returns true if the supplied region supports mobile number portability. Returns false for invalid, unknown or regions that don't support mobile number portability. Arguments: region_code -- the region for which we want to know whether it support...
python
def is_mobile_number_portable_region(region_code): """Returns true if the supplied region supports mobile number portability. Returns false for invalid, unknown or regions that don't support mobile number portability. Arguments: region_code -- the region for which we want to know whether it support...
[ "def", "is_mobile_number_portable_region", "(", "region_code", ")", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(", "region_code", ",", "None", ")", "if", "metadata", "is", "None", ":", "return", "False", "return", "metadata", ".", "mobile_...
Returns true if the supplied region supports mobile number portability. Returns false for invalid, unknown or regions that don't support mobile number portability. Arguments: region_code -- the region for which we want to know whether it supports mobile number portability or not.
[ "Returns", "true", "if", "the", "supplied", "region", "supports", "mobile", "number", "portability", ".", "Returns", "false", "for", "invalid", "unknown", "or", "regions", "that", "don", "t", "support", "mobile", "number", "portability", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumberutil.py#L3140-L3152
220,874
daviddrysdale/python-phonenumbers
python/phonenumbers/timezone.py
time_zones_for_geographical_number
def time_zones_for_geographical_number(numobj): """Returns a list of time zones to which a phone number belongs. This method assumes the validity of the number passed in has already been checked, and that the number is geo-localizable. We consider fixed-line and mobile numbers possible candidates for g...
python
def time_zones_for_geographical_number(numobj): """Returns a list of time zones to which a phone number belongs. This method assumes the validity of the number passed in has already been checked, and that the number is geo-localizable. We consider fixed-line and mobile numbers possible candidates for g...
[ "def", "time_zones_for_geographical_number", "(", "numobj", ")", ":", "e164_num", "=", "format_number", "(", "numobj", ",", "PhoneNumberFormat", ".", "E164", ")", "if", "not", "e164_num", ".", "startswith", "(", "U_PLUS", ")", ":", "# pragma no cover", "# Can only...
Returns a list of time zones to which a phone number belongs. This method assumes the validity of the number passed in has already been checked, and that the number is geo-localizable. We consider fixed-line and mobile numbers possible candidates for geo-localization. Arguments: numobj -- a valid ...
[ "Returns", "a", "list", "of", "time", "zones", "to", "which", "a", "phone", "number", "belongs", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/timezone.py#L64-L86
220,875
daviddrysdale/python-phonenumbers
python/phonenumbers/unicode_util.py
is_letter
def is_letter(uni_char): """Determine whether the given Unicode character is a Unicode letter""" category = Category.get(uni_char) return (category == Category.UPPERCASE_LETTER or category == Category.LOWERCASE_LETTER or category == Category.TITLECASE_LETTER or category =...
python
def is_letter(uni_char): """Determine whether the given Unicode character is a Unicode letter""" category = Category.get(uni_char) return (category == Category.UPPERCASE_LETTER or category == Category.LOWERCASE_LETTER or category == Category.TITLECASE_LETTER or category =...
[ "def", "is_letter", "(", "uni_char", ")", ":", "category", "=", "Category", ".", "get", "(", "uni_char", ")", "return", "(", "category", "==", "Category", ".", "UPPERCASE_LETTER", "or", "category", "==", "Category", ".", "LOWERCASE_LETTER", "or", "category", ...
Determine whether the given Unicode character is a Unicode letter
[ "Determine", "whether", "the", "given", "Unicode", "character", "is", "a", "Unicode", "letter" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/unicode_util.py#L128-L135
220,876
daviddrysdale/python-phonenumbers
python/phonenumbers/unicode_util.py
digit
def digit(uni_char, default_value=None): """Returns the digit value assigned to the Unicode character uni_char as integer. If no such value is defined, default is returned, or, if not given, ValueError is raised.""" uni_char = unicod(uni_char) # Force to Unicode. if default_value is not None: ...
python
def digit(uni_char, default_value=None): """Returns the digit value assigned to the Unicode character uni_char as integer. If no such value is defined, default is returned, or, if not given, ValueError is raised.""" uni_char = unicod(uni_char) # Force to Unicode. if default_value is not None: ...
[ "def", "digit", "(", "uni_char", ",", "default_value", "=", "None", ")", ":", "uni_char", "=", "unicod", "(", "uni_char", ")", "# Force to Unicode.", "if", "default_value", "is", "not", "None", ":", "return", "unicodedata", ".", "digit", "(", "uni_char", ","...
Returns the digit value assigned to the Unicode character uni_char as integer. If no such value is defined, default is returned, or, if not given, ValueError is raised.
[ "Returns", "the", "digit", "value", "assigned", "to", "the", "Unicode", "character", "uni_char", "as", "integer", ".", "If", "no", "such", "value", "is", "defined", "default", "is", "returned", "or", "if", "not", "given", "ValueError", "is", "raised", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/unicode_util.py#L397-L405
220,877
daviddrysdale/python-phonenumbers
python/phonenumbers/unicode_util.py
Block.get
def get(cls, uni_char): """Return the Unicode block of the given Unicode character""" uni_char = unicod(uni_char) # Force to Unicode code_point = ord(uni_char) if Block._RANGE_KEYS is None: Block._RANGE_KEYS = sorted(Block._RANGES.keys()) idx = bisect.bisect_left(Blo...
python
def get(cls, uni_char): """Return the Unicode block of the given Unicode character""" uni_char = unicod(uni_char) # Force to Unicode code_point = ord(uni_char) if Block._RANGE_KEYS is None: Block._RANGE_KEYS = sorted(Block._RANGES.keys()) idx = bisect.bisect_left(Blo...
[ "def", "get", "(", "cls", ",", "uni_char", ")", ":", "uni_char", "=", "unicod", "(", "uni_char", ")", "# Force to Unicode", "code_point", "=", "ord", "(", "uni_char", ")", "if", "Block", ".", "_RANGE_KEYS", "is", "None", ":", "Block", ".", "_RANGE_KEYS", ...
Return the Unicode block of the given Unicode character
[ "Return", "the", "Unicode", "block", "of", "the", "given", "Unicode", "character" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/unicode_util.py#L378-L394
220,878
daviddrysdale/python-phonenumbers
python/phonenumbers/carrier.py
_is_mobile
def _is_mobile(ntype): """Checks if the supplied number type supports carrier lookup""" return (ntype == PhoneNumberType.MOBILE or ntype == PhoneNumberType.FIXED_LINE_OR_MOBILE or ntype == PhoneNumberType.PAGER)
python
def _is_mobile(ntype): """Checks if the supplied number type supports carrier lookup""" return (ntype == PhoneNumberType.MOBILE or ntype == PhoneNumberType.FIXED_LINE_OR_MOBILE or ntype == PhoneNumberType.PAGER)
[ "def", "_is_mobile", "(", "ntype", ")", ":", "return", "(", "ntype", "==", "PhoneNumberType", ".", "MOBILE", "or", "ntype", "==", "PhoneNumberType", ".", "FIXED_LINE_OR_MOBILE", "or", "ntype", "==", "PhoneNumberType", ".", "PAGER", ")" ]
Checks if the supplied number type supports carrier lookup
[ "Checks", "if", "the", "supplied", "number", "type", "supports", "carrier", "lookup" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/carrier.py#L136-L140
220,879
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumber.py
PhoneNumber.clear
def clear(self): """Erase the contents of the object""" self.country_code = None self.national_number = None self.extension = None self.italian_leading_zero = None self.number_of_leading_zeros = None self.raw_input = None self.country_code_source = Country...
python
def clear(self): """Erase the contents of the object""" self.country_code = None self.national_number = None self.extension = None self.italian_leading_zero = None self.number_of_leading_zeros = None self.raw_input = None self.country_code_source = Country...
[ "def", "clear", "(", "self", ")", ":", "self", ".", "country_code", "=", "None", "self", ".", "national_number", "=", "None", "self", ".", "extension", "=", "None", "self", ".", "italian_leading_zero", "=", "None", "self", ".", "number_of_leading_zeros", "="...
Erase the contents of the object
[ "Erase", "the", "contents", "of", "the", "object" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumber.py#L168-L177
220,880
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumber.py
PhoneNumber.merge_from
def merge_from(self, other): """Merge information from another PhoneNumber object into this one.""" if other.country_code is not None: self.country_code = other.country_code if other.national_number is not None: self.national_number = other.national_number if othe...
python
def merge_from(self, other): """Merge information from another PhoneNumber object into this one.""" if other.country_code is not None: self.country_code = other.country_code if other.national_number is not None: self.national_number = other.national_number if othe...
[ "def", "merge_from", "(", "self", ",", "other", ")", ":", "if", "other", ".", "country_code", "is", "not", "None", ":", "self", ".", "country_code", "=", "other", ".", "country_code", "if", "other", ".", "national_number", "is", "not", "None", ":", "self...
Merge information from another PhoneNumber object into this one.
[ "Merge", "information", "from", "another", "PhoneNumber", "object", "into", "this", "one", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumber.py#L179-L196
220,881
daviddrysdale/python-phonenumbers
python/phonenumbers/util.py
mutating_method
def mutating_method(func): """Decorator for methods that are allowed to modify immutable objects""" def wrapper(self, *__args, **__kwargs): old_mutable = self._mutable self._mutable = True try: # Call the wrapped function return func(self, *__args, **__kwargs) ...
python
def mutating_method(func): """Decorator for methods that are allowed to modify immutable objects""" def wrapper(self, *__args, **__kwargs): old_mutable = self._mutable self._mutable = True try: # Call the wrapped function return func(self, *__args, **__kwargs) ...
[ "def", "mutating_method", "(", "func", ")", ":", "def", "wrapper", "(", "self", ",", "*", "__args", ",", "*", "*", "__kwargs", ")", ":", "old_mutable", "=", "self", ".", "_mutable", "self", ".", "_mutable", "=", "True", "try", ":", "# Call the wrapped fu...
Decorator for methods that are allowed to modify immutable objects
[ "Decorator", "for", "methods", "that", "are", "allowed", "to", "modify", "immutable", "objects" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/util.py#L169-L179
220,882
daviddrysdale/python-phonenumbers
python/phonenumbers/re_util.py
fullmatch
def fullmatch(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object if the whole string matches, or None if no match was found.""" # Build a version of the pattern with a non-capturing group around it. # This is needed to get m.end() to correctly rep...
python
def fullmatch(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object if the whole string matches, or None if no match was found.""" # Build a version of the pattern with a non-capturing group around it. # This is needed to get m.end() to correctly rep...
[ "def", "fullmatch", "(", "pattern", ",", "string", ",", "flags", "=", "0", ")", ":", "# Build a version of the pattern with a non-capturing group around it.", "# This is needed to get m.end() to correctly report the size of the", "# matched expression (as per the final doctest above).", ...
Try to apply the pattern at the start of the string, returning a match object if the whole string matches, or None if no match was found.
[ "Try", "to", "apply", "the", "pattern", "at", "the", "start", "of", "the", "string", "returning", "a", "match", "object", "if", "the", "whole", "string", "matches", "or", "None", "if", "no", "match", "was", "found", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/re_util.py#L27-L39
220,883
daviddrysdale/python-phonenumbers
tools/python/buildprefixdata.py
load_locale_prefixdata_file
def load_locale_prefixdata_file(prefixdata, filename, locale=None, overall_prefix=None, separator=None): """Load per-prefix data from the given file, for the given locale and prefix. We assume that this file: - is encoded in UTF-8 - may have comment lines (starting with #) and blank lines - has ...
python
def load_locale_prefixdata_file(prefixdata, filename, locale=None, overall_prefix=None, separator=None): """Load per-prefix data from the given file, for the given locale and prefix. We assume that this file: - is encoded in UTF-8 - may have comment lines (starting with #) and blank lines - has ...
[ "def", "load_locale_prefixdata_file", "(", "prefixdata", ",", "filename", ",", "locale", "=", "None", ",", "overall_prefix", "=", "None", ",", "separator", "=", "None", ")", ":", "with", "open", "(", "filename", ",", "\"rb\"", ")", "as", "infile", ":", "li...
Load per-prefix data from the given file, for the given locale and prefix. We assume that this file: - is encoded in UTF-8 - may have comment lines (starting with #) and blank lines - has data lines of the form '<prefix>|<stringdata>' - contains only data for prefixes that are extensions of the...
[ "Load", "per", "-", "prefix", "data", "from", "the", "given", "file", "for", "the", "given", "locale", "and", "prefix", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildprefixdata.py#L83-L128
220,884
daviddrysdale/python-phonenumbers
tools/python/buildprefixdata.py
load_locale_prefixdata
def load_locale_prefixdata(indir, separator=None): """Load per-prefix data from the given top-level directory. Prefix data is assumed to be held in files <indir>/<locale>/<prefix>.txt. The same prefix may occur in multiple files, giving the prefix's description in different locales. """ prefixd...
python
def load_locale_prefixdata(indir, separator=None): """Load per-prefix data from the given top-level directory. Prefix data is assumed to be held in files <indir>/<locale>/<prefix>.txt. The same prefix may occur in multiple files, giving the prefix's description in different locales. """ prefixd...
[ "def", "load_locale_prefixdata", "(", "indir", ",", "separator", "=", "None", ")", ":", "prefixdata", "=", "{", "}", "# prefix => dict mapping locale to description", "for", "locale", "in", "os", ".", "listdir", "(", "indir", ")", ":", "if", "not", "os", ".", ...
Load per-prefix data from the given top-level directory. Prefix data is assumed to be held in files <indir>/<locale>/<prefix>.txt. The same prefix may occur in multiple files, giving the prefix's description in different locales.
[ "Load", "per", "-", "prefix", "data", "from", "the", "given", "top", "-", "level", "directory", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildprefixdata.py#L131-L145
220,885
daviddrysdale/python-phonenumbers
tools/python/buildprefixdata.py
output_prefixdata_code
def output_prefixdata_code(prefixdata, outfilename, module_prefix, varprefix, per_locale, chunks): """Output the per-prefix data in Python form to the given file """ sorted_keys = sorted(prefixdata.keys()) total_keys = len(sorted_keys) if chunks == -1: chunk_size = PREFIXDATA_CHUNK_SIZE ...
python
def output_prefixdata_code(prefixdata, outfilename, module_prefix, varprefix, per_locale, chunks): """Output the per-prefix data in Python form to the given file """ sorted_keys = sorted(prefixdata.keys()) total_keys = len(sorted_keys) if chunks == -1: chunk_size = PREFIXDATA_CHUNK_SIZE ...
[ "def", "output_prefixdata_code", "(", "prefixdata", ",", "outfilename", ",", "module_prefix", ",", "varprefix", ",", "per_locale", ",", "chunks", ")", ":", "sorted_keys", "=", "sorted", "(", "prefixdata", ".", "keys", "(", ")", ")", "total_keys", "=", "len", ...
Output the per-prefix data in Python form to the given file
[ "Output", "the", "per", "-", "prefix", "data", "in", "Python", "form", "to", "the", "given", "file" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildprefixdata.py#L164-L200
220,886
daviddrysdale/python-phonenumbers
tools/python/buildprefixdata.py
_standalone
def _standalone(argv): """Parse the given input directory and emit generated code.""" varprefix = "GEOCODE" per_locale = True separator = None chunks = -1 try: opts, args = getopt.getopt(argv, "hv:fs:c:", ("help", "var=", "flat", "sep=", "chunks=")) except getopt.GetoptError: ...
python
def _standalone(argv): """Parse the given input directory and emit generated code.""" varprefix = "GEOCODE" per_locale = True separator = None chunks = -1 try: opts, args = getopt.getopt(argv, "hv:fs:c:", ("help", "var=", "flat", "sep=", "chunks=")) except getopt.GetoptError: ...
[ "def", "_standalone", "(", "argv", ")", ":", "varprefix", "=", "\"GEOCODE\"", "per_locale", "=", "True", "separator", "=", "None", "chunks", "=", "-", "1", "try", ":", "opts", ",", "args", "=", "getopt", ".", "getopt", "(", "argv", ",", "\"hv:fs:c:\"", ...
Parse the given input directory and emit generated code.
[ "Parse", "the", "given", "input", "directory", "and", "emit", "generated", "code", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/tools/python/buildprefixdata.py#L223-L258
220,887
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
_limit
def _limit(lower, upper): """Returns a regular expression quantifier with an upper and lower limit.""" if ((lower < 0) or (upper <= 0) or (upper < lower)): raise Exception("Illegal argument to _limit") return unicod("{%d,%d}") % (lower, upper)
python
def _limit(lower, upper): """Returns a regular expression quantifier with an upper and lower limit.""" if ((lower < 0) or (upper <= 0) or (upper < lower)): raise Exception("Illegal argument to _limit") return unicod("{%d,%d}") % (lower, upper)
[ "def", "_limit", "(", "lower", ",", "upper", ")", ":", "if", "(", "(", "lower", "<", "0", ")", "or", "(", "upper", "<=", "0", ")", "or", "(", "upper", "<", "lower", ")", ")", ":", "raise", "Exception", "(", "\"Illegal argument to _limit\"", ")", "r...
Returns a regular expression quantifier with an upper and lower limit.
[ "Returns", "a", "regular", "expression", "quantifier", "with", "an", "upper", "and", "lower", "limit", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L57-L61
220,888
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
_verify
def _verify(leniency, numobj, candidate, matcher): """Returns True if number is a verified number according to the leniency.""" if leniency == Leniency.POSSIBLE: return is_possible_number(numobj) elif leniency == Leniency.VALID: if (not is_valid_number(numobj) or not _contain...
python
def _verify(leniency, numobj, candidate, matcher): """Returns True if number is a verified number according to the leniency.""" if leniency == Leniency.POSSIBLE: return is_possible_number(numobj) elif leniency == Leniency.VALID: if (not is_valid_number(numobj) or not _contain...
[ "def", "_verify", "(", "leniency", ",", "numobj", ",", "candidate", ",", "matcher", ")", ":", "if", "leniency", "==", "Leniency", ".", "POSSIBLE", ":", "return", "is_possible_number", "(", "numobj", ")", "elif", "leniency", "==", "Leniency", ".", "VALID", ...
Returns True if number is a verified number according to the leniency.
[ "Returns", "True", "if", "number", "is", "a", "verified", "number", "according", "to", "the", "leniency", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L209-L224
220,889
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
_get_national_number_groups_without_pattern
def _get_national_number_groups_without_pattern(numobj): """Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that would be formatted together following standard formatting rules.""" # This will be in the format +CC-D...
python
def _get_national_number_groups_without_pattern(numobj): """Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that would be formatted together following standard formatting rules.""" # This will be in the format +CC-D...
[ "def", "_get_national_number_groups_without_pattern", "(", "numobj", ")", ":", "# This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of", "# digits.", "rfc3966_format", "=", "format_number", "(", "numobj", ",", "PhoneNumberFormat", ".", "RFC3966", "...
Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that would be formatted together following standard formatting rules.
[ "Helper", "method", "to", "get", "the", "national", "-", "number", "part", "of", "a", "number", "formatted", "without", "any", "national", "prefix", "and", "return", "it", "as", "a", "set", "of", "digit", "blocks", "that", "would", "be", "formatted", "toge...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L337-L352
220,890
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
_get_national_number_groups
def _get_national_number_groups(numobj, formatting_pattern): """Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that should be formatted together according to the formatting pattern passed in.""" # If a format is pr...
python
def _get_national_number_groups(numobj, formatting_pattern): """Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that should be formatted together according to the formatting pattern passed in.""" # If a format is pr...
[ "def", "_get_national_number_groups", "(", "numobj", ",", "formatting_pattern", ")", ":", "# If a format is provided, we format the NSN only, and split that according to the separator.", "nsn", "=", "national_significant_number", "(", "numobj", ")", "return", "_format_nsn_using_patte...
Helper method to get the national-number part of a number, formatted without any national prefix, and return it as a set of digit blocks that should be formatted together according to the formatting pattern passed in.
[ "Helper", "method", "to", "get", "the", "national", "-", "number", "part", "of", "a", "number", "formatted", "without", "any", "national", "prefix", "and", "return", "it", "as", "a", "set", "of", "digit", "blocks", "that", "should", "be", "formatted", "tog...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L355-L362
220,891
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._find
def _find(self, index): """Attempts to find the next subsequence in the searched sequence on or after index that represents a phone number. Returns the next match, None if none was found. Arguments: index -- The search index to start searching at. Returns the phone number match ...
python
def _find(self, index): """Attempts to find the next subsequence in the searched sequence on or after index that represents a phone number. Returns the next match, None if none was found. Arguments: index -- The search index to start searching at. Returns the phone number match ...
[ "def", "_find", "(", "self", ",", "index", ")", ":", "match", "=", "_PATTERN", ".", "search", "(", "self", ".", "text", ",", "index", ")", "while", "self", ".", "_max_tries", ">", "0", "and", "match", "is", "not", "None", ":", "start", "=", "match"...
Attempts to find the next subsequence in the searched sequence on or after index that represents a phone number. Returns the next match, None if none was found. Arguments: index -- The search index to start searching at. Returns the phone number match found, None if none can be found.
[ "Attempts", "to", "find", "the", "next", "subsequence", "in", "the", "searched", "sequence", "on", "or", "after", "index", "that", "represents", "a", "phone", "number", ".", "Returns", "the", "next", "match", "None", "if", "none", "was", "found", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L497-L524
220,892
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._trim_after_first_match
def _trim_after_first_match(self, pattern, candidate): """Trims away any characters after the first match of pattern in candidate, returning the trimmed version.""" trailing_chars_match = pattern.search(candidate) if trailing_chars_match: candidate = candidate[:trailing_chars...
python
def _trim_after_first_match(self, pattern, candidate): """Trims away any characters after the first match of pattern in candidate, returning the trimmed version.""" trailing_chars_match = pattern.search(candidate) if trailing_chars_match: candidate = candidate[:trailing_chars...
[ "def", "_trim_after_first_match", "(", "self", ",", "pattern", ",", "candidate", ")", ":", "trailing_chars_match", "=", "pattern", ".", "search", "(", "candidate", ")", "if", "trailing_chars_match", ":", "candidate", "=", "candidate", "[", ":", "trailing_chars_mat...
Trims away any characters after the first match of pattern in candidate, returning the trimmed version.
[ "Trims", "away", "any", "characters", "after", "the", "first", "match", "of", "pattern", "in", "candidate", "returning", "the", "trimmed", "version", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L526-L532
220,893
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._is_latin_letter
def _is_latin_letter(cls, letter): """Helper method to determine if a character is a Latin-script letter or not. For our purposes, combining marks should also return True since we assume they have been added to a preceding Latin character.""" # Combining marks are a subset of non-spacing...
python
def _is_latin_letter(cls, letter): """Helper method to determine if a character is a Latin-script letter or not. For our purposes, combining marks should also return True since we assume they have been added to a preceding Latin character.""" # Combining marks are a subset of non-spacing...
[ "def", "_is_latin_letter", "(", "cls", ",", "letter", ")", ":", "# Combining marks are a subset of non-spacing-mark", "if", "(", "not", "is_letter", "(", "letter", ")", "and", "Category", ".", "get", "(", "letter", ")", "!=", "Category", ".", "NON_SPACING_MARK", ...
Helper method to determine if a character is a Latin-script letter or not. For our purposes, combining marks should also return True since we assume they have been added to a preceding Latin character.
[ "Helper", "method", "to", "determine", "if", "a", "character", "is", "a", "Latin", "-", "script", "letter", "or", "not", ".", "For", "our", "purposes", "combining", "marks", "should", "also", "return", "True", "since", "we", "assume", "they", "have", "been...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L535-L549
220,894
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._extract_match
def _extract_match(self, candidate, offset): """Attempts to extract a match from a candidate string. Arguments: candidate -- The candidate text that might contain a phone number. offset -- The offset of candidate within self.text Returns the match found, None if none can be foun...
python
def _extract_match(self, candidate, offset): """Attempts to extract a match from a candidate string. Arguments: candidate -- The candidate text that might contain a phone number. offset -- The offset of candidate within self.text Returns the match found, None if none can be foun...
[ "def", "_extract_match", "(", "self", ",", "candidate", ",", "offset", ")", ":", "# Skip a match that is more likely a publication page reference or a", "# date.", "if", "(", "_SLASH_SEPARATED_DATES", ".", "search", "(", "candidate", ")", ")", ":", "return", "None", "...
Attempts to extract a match from a candidate string. Arguments: candidate -- The candidate text that might contain a phone number. offset -- The offset of candidate within self.text Returns the match found, None if none can be found
[ "Attempts", "to", "extract", "a", "match", "from", "a", "candidate", "string", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L556-L582
220,895
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._extract_inner_match
def _extract_inner_match(self, candidate, offset): """Attempts to extract a match from candidate if the whole candidate does not qualify as a match. Arguments: candidate -- The candidate text that might contain a phone number offset -- The current offset of candidate within text...
python
def _extract_inner_match(self, candidate, offset): """Attempts to extract a match from candidate if the whole candidate does not qualify as a match. Arguments: candidate -- The candidate text that might contain a phone number offset -- The current offset of candidate within text...
[ "def", "_extract_inner_match", "(", "self", ",", "candidate", ",", "offset", ")", ":", "for", "possible_inner_match", "in", "_INNER_MATCHES", ":", "group_match", "=", "possible_inner_match", ".", "search", "(", "candidate", ")", "is_first_match", "=", "True", "whi...
Attempts to extract a match from candidate if the whole candidate does not qualify as a match. Arguments: candidate -- The candidate text that might contain a phone number offset -- The current offset of candidate within text Returns the match found, None if none can be found
[ "Attempts", "to", "extract", "a", "match", "from", "candidate", "if", "the", "whole", "candidate", "does", "not", "qualify", "as", "a", "match", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L584-L613
220,896
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher._parse_and_verify
def _parse_and_verify(self, candidate, offset): """Parses a phone number from the candidate using phonenumberutil.parse and verifies it matches the requested leniency. If parsing and verification succeed, a corresponding PhoneNumberMatch is returned, otherwise this method returns None. ...
python
def _parse_and_verify(self, candidate, offset): """Parses a phone number from the candidate using phonenumberutil.parse and verifies it matches the requested leniency. If parsing and verification succeed, a corresponding PhoneNumberMatch is returned, otherwise this method returns None. ...
[ "def", "_parse_and_verify", "(", "self", ",", "candidate", ",", "offset", ")", ":", "try", ":", "# Check the candidate doesn't contain any formatting which would", "# indicate that it really isn't a phone number.", "if", "(", "not", "fullmatch", "(", "_MATCHING_BRACKETS", ","...
Parses a phone number from the candidate using phonenumberutil.parse and verifies it matches the requested leniency. If parsing and verification succeed, a corresponding PhoneNumberMatch is returned, otherwise this method returns None. Arguments: candidate -- The candidate match. ...
[ "Parses", "a", "phone", "number", "from", "the", "candidate", "using", "phonenumberutil", ".", "parse", "and", "verifies", "it", "matches", "the", "requested", "leniency", ".", "If", "parsing", "and", "verification", "succeed", "a", "corresponding", "PhoneNumberMa...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L615-L667
220,897
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher.has_next
def has_next(self): """Indicates whether there is another match available""" if self._state == PhoneNumberMatcher._NOT_READY: self._last_match = self._find(self._search_index) if self._last_match is None: self._state = PhoneNumberMatcher._DONE else: ...
python
def has_next(self): """Indicates whether there is another match available""" if self._state == PhoneNumberMatcher._NOT_READY: self._last_match = self._find(self._search_index) if self._last_match is None: self._state = PhoneNumberMatcher._DONE else: ...
[ "def", "has_next", "(", "self", ")", ":", "if", "self", ".", "_state", "==", "PhoneNumberMatcher", ".", "_NOT_READY", ":", "self", ".", "_last_match", "=", "self", ".", "_find", "(", "self", ".", "_search_index", ")", "if", "self", ".", "_last_match", "i...
Indicates whether there is another match available
[ "Indicates", "whether", "there", "is", "another", "match", "available" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L690-L699
220,898
daviddrysdale/python-phonenumbers
python/phonenumbers/phonenumbermatcher.py
PhoneNumberMatcher.next
def next(self): """Return the next match; raises Exception if no next match available""" # Check the state and find the next match as a side-effect if necessary. if not self.has_next(): raise StopIteration("No next match") # Don't retain that memory any longer than necessary....
python
def next(self): """Return the next match; raises Exception if no next match available""" # Check the state and find the next match as a side-effect if necessary. if not self.has_next(): raise StopIteration("No next match") # Don't retain that memory any longer than necessary....
[ "def", "next", "(", "self", ")", ":", "# Check the state and find the next match as a side-effect if necessary.", "if", "not", "self", ".", "has_next", "(", ")", ":", "raise", "StopIteration", "(", "\"No next match\"", ")", "# Don't retain that memory any longer than necessar...
Return the next match; raises Exception if no next match available
[ "Return", "the", "next", "match", ";", "raises", "Exception", "if", "no", "next", "match", "available" ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/phonenumbermatcher.py#L701-L710
220,899
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
is_possible_short_number_for_region
def is_possible_short_number_for_region(short_numobj, region_dialing_from): """Check whether a short number is a possible number when dialled from a region. This provides a more lenient check than is_valid_short_number_for_region. Arguments: short_numobj -- the short number to check as a PhoneNumbe...
python
def is_possible_short_number_for_region(short_numobj, region_dialing_from): """Check whether a short number is a possible number when dialled from a region. This provides a more lenient check than is_valid_short_number_for_region. Arguments: short_numobj -- the short number to check as a PhoneNumbe...
[ "def", "is_possible_short_number_for_region", "(", "short_numobj", ",", "region_dialing_from", ")", ":", "if", "not", "_region_dialing_from_matches_number", "(", "short_numobj", ",", "region_dialing_from", ")", ":", "return", "False", "metadata", "=", "PhoneMetadata", "."...
Check whether a short number is a possible number when dialled from a region. This provides a more lenient check than is_valid_short_number_for_region. Arguments: short_numobj -- the short number to check as a PhoneNumber object. region_dialing_from -- the region from which the number is dialed ...
[ "Check", "whether", "a", "short", "number", "is", "a", "possible", "number", "when", "dialled", "from", "a", "region", ".", "This", "provides", "a", "more", "lenient", "check", "than", "is_valid_short_number_for_region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L66-L83