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
partition
stringclasses
1 value
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
train
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
train
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", ")", ":", "if", "number_desc", "is", "None", ":", "return", "False", "actual_length", "=", "len", "(", "national_number", ")", "possible_lengths", "=", "number_desc", ".", "possible_lengt...
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
train
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
train
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
train
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", ":", "metadata", "=", "PhoneMetadata", ".", "metadata_for_region", "(...
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
train
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
train
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
train
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
train
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
train
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", "if", "not", "_has_valid_country_calling_code", "(", ...
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
train
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
train
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", ":", "return", "(", "0", ",", "number", ")", "for", "ii", "in", "range", "(", "1", ",", "min", "("...
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
train
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", "possible_cou...
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
train
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", "(", ")", "digit_match", "=", "_CAPTURING_DIGIT_PATTERN", "....
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
train
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", "match", "and", "_is_viable_phone_number", "(", "number", "[", ":", "match", ".", "start", "(", ")", "]", ")", ":", "for", "...
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
train
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", "number", "is", "None", "or", "len", "(", "number", ")", "==", "0", ":", "return", "False", "matc...
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
train
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
train
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
train
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
train
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
train
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", ")", ":", "numobj1", "=", "_copy_core_fields_only", "(", "numobj1_in", ")", "numobj2", "=", "_copy_core_fields_only", "(", "numobj2_in", ")", "if", "(", "numobj1", ".", "extension", "is", "not", ...
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
train
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", ")", "return", "nn1", ".", "endswith", "(", "nn...
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
train
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
train
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", ")", ":", "try", ":", "numobj2", "=", "parse", "(", "number2", ",", "UNKNOWN_REGION", ")", "return", "_is_number_match_OO", "(", "numobj1", ",", "numobj2", ")", "except", "NumberParseException", ":", ...
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
train
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
train
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", ":", "return", "True", "nsn", "="...
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
train
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
train
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", ")", ":", "raise", "Exception", "(", "...
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
train
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
train
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", ")", "if", "default_value", "is", "not", "None", ":", "return", "unicodedata", ".", "digit", "(", "uni_char", ",", "default_value", ")...
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
train
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", ")", "code_point", "=", "ord", "(", "uni_char", ")", "if", "Block", ".", "_RANGE_KEYS", "is", "None", ":", "Block", ".", "_RANGE_KEYS", "=", "sorted", "(",...
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
train
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
train
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
train
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
train
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", ":", "return", "func", "(", ...
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
train
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", ")", ":", "grouped_pattern", "=", "re", ".", "compile", "(", "\"^(?:%s)$\"", "%", "pattern", ".", "pattern", ",", "pattern", ".", "flags", ")", "m", "=", "grouped_pattern", ".", ...
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
train
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
train
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", "=", "{", "}", "for", "locale", "in", "os", ".", "listdir", "(", "indir", ")", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "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
train
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
train
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
train
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
train
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
train
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", ")", ":", "rfc3966_format", "=", "format_number", "(", "numobj", ",", "PhoneNumberFormat", ".", "RFC3966", ")", "end_index", "=", "rfc3966_format", ".", "find", "(", "U_SEMICOLON", ")", "if", "end_...
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
train
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", ")", ":", "nsn", "=", "national_significant_number", "(", "numobj", ")", "return", "_format_nsn_using_pattern", "(", "nsn", ",", "formatting_pattern", ",", "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 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
train
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
train
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
train
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", ")", ":", "if", "(", "not", "is_letter", "(", "letter", ")", "and", "Category", ".", "get", "(", "letter", ")", "!=", "Category", ".", "NON_SPACING_MARK", ")", ":", "return", "False", "block", "=", ...
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
train
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", ")", ":", "if", "(", "_SLASH_SEPARATED_DATES", ".", "search", "(", "candidate", ")", ")", ":", "return", "None", "if", "_TIME_STAMPS", ".", "search", "(", "candidate", ")", ":", "follow...
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
train
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
train
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", ":", "if", "(", "not", "fullmatch", "(", "_MATCHING_BRACKETS", ",", "candidate", ")", "or", "_PUB_PAGES", ".", "search", "(", "candidate", ")", ")", ":", "return", ...
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
train
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
train
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", ")", ":", "if", "not", "self", ".", "has_next", "(", ")", ":", "raise", "StopIteration", "(", "\"No next match\"", ")", "result", "=", "self", ".", "_last_match", "self", ".", "_last_match", "=", "None", "self", ".", "_state",...
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
train
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
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
is_possible_short_number
def is_possible_short_number(numobj): """Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns True if it's possible in any of them. This provides a more lenient check than is_valid_short_number. Arguments: numobj -- the short ...
python
def is_possible_short_number(numobj): """Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns True if it's possible in any of them. This provides a more lenient check than is_valid_short_number. Arguments: numobj -- the short ...
[ "def", "is_possible_short_number", "(", "numobj", ")", ":", "region_codes", "=", "region_codes_for_country_code", "(", "numobj", ".", "country_code", ")", "short_number_len", "=", "len", "(", "national_significant_number", "(", "numobj", ")", ")", "for", "region", "...
Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns True if it's possible in any of them. This provides a more lenient check than is_valid_short_number. Arguments: numobj -- the short number to check Return whether the numbe...
[ "Check", "whether", "a", "short", "number", "is", "a", "possible", "number", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L86-L107
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
is_valid_short_number_for_region
def is_valid_short_number_for_region(short_numobj, region_dialing_from): """Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. Arguments: short_numobj -- th...
python
def is_valid_short_number_for_region(short_numobj, region_dialing_from): """Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. Arguments: short_numobj -- th...
[ "def", "is_valid_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", ".", ...
Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. Arguments: short_numobj -- the short number to check as a PhoneNumber object. region_dialing_from -- the ...
[ "Tests", "whether", "a", "short", "number", "matches", "a", "valid", "pattern", "in", "a", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L110-L134
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
is_valid_short_number
def is_valid_short_number(numobj): """Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns True if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking a...
python
def is_valid_short_number(numobj): """Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns True if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking a...
[ "def", "is_valid_short_number", "(", "numobj", ")", ":", "region_codes", "=", "region_codes_for_country_code", "(", "numobj", ".", "country_code", ")", "region_code", "=", "_region_code_for_short_number_from_region_list", "(", "numobj", ",", "region_codes", ")", "if", "...
Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns True if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. See is_valid_shor...
[ "Tests", "whether", "a", "short", "number", "matches", "a", "valid", "pattern", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L137-L156
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
_region_code_for_short_number_from_region_list
def _region_code_for_short_number_from_region_list(numobj, region_codes): """Helper method to get the region code for a given phone number, from a list of possible region codes. If the list contains more than one region, the first region for which the number is valid is returned. """ if len(region_c...
python
def _region_code_for_short_number_from_region_list(numobj, region_codes): """Helper method to get the region code for a given phone number, from a list of possible region codes. If the list contains more than one region, the first region for which the number is valid is returned. """ if len(region_c...
[ "def", "_region_code_for_short_number_from_region_list", "(", "numobj", ",", "region_codes", ")", ":", "if", "len", "(", "region_codes", ")", "==", "0", ":", "return", "None", "elif", "len", "(", "region_codes", ")", "==", "1", ":", "return", "region_codes", "...
Helper method to get the region code for a given phone number, from a list of possible region codes. If the list contains more than one region, the first region for which the number is valid is returned.
[ "Helper", "method", "to", "get", "the", "region", "code", "for", "a", "given", "phone", "number", "from", "a", "list", "of", "possible", "region", "codes", ".", "If", "the", "list", "contains", "more", "than", "one", "region", "the", "first", "region", "...
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L259-L274
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
_example_short_number
def _example_short_number(region_code): """Gets a valid short number for the specified region. Arguments: region_code -- the region for which an example short number is needed. Returns a valid short number for the specified region. Returns an empty string when the metadata does not contain such in...
python
def _example_short_number(region_code): """Gets a valid short number for the specified region. Arguments: region_code -- the region for which an example short number is needed. Returns a valid short number for the specified region. Returns an empty string when the metadata does not contain such in...
[ "def", "_example_short_number", "(", "region_code", ")", ":", "metadata", "=", "PhoneMetadata", ".", "short_metadata_for_region", "(", "region_code", ")", "if", "metadata", "is", "None", ":", "return", "U_EMPTY_STRING", "desc", "=", "metadata", ".", "short_code", ...
Gets a valid short number for the specified region. Arguments: region_code -- the region for which an example short number is needed. Returns a valid short number for the specified region. Returns an empty string when the metadata does not contain such information.
[ "Gets", "a", "valid", "short", "number", "for", "the", "specified", "region", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L277-L292
train
daviddrysdale/python-phonenumbers
python/phonenumbers/shortnumberinfo.py
_example_short_number_for_cost
def _example_short_number_for_cost(region_code, cost): """Gets a valid short number for the specified cost category. Arguments: region_code -- the region for which an example short number is needed. cost -- the cost category of number that is needed. Returns a valid short number for the specified ...
python
def _example_short_number_for_cost(region_code, cost): """Gets a valid short number for the specified cost category. Arguments: region_code -- the region for which an example short number is needed. cost -- the cost category of number that is needed. Returns a valid short number for the specified ...
[ "def", "_example_short_number_for_cost", "(", "region_code", ",", "cost", ")", ":", "metadata", "=", "PhoneMetadata", ".", "short_metadata_for_region", "(", "region_code", ")", "if", "metadata", "is", "None", ":", "return", "U_EMPTY_STRING", "desc", "=", "None", "...
Gets a valid short number for the specified cost category. Arguments: region_code -- the region for which an example short number is needed. cost -- the cost category of number that is needed. Returns a valid short number for the specified region and cost category. Returns an empty string when the...
[ "Gets", "a", "valid", "short", "number", "for", "the", "specified", "cost", "category", "." ]
9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20
https://github.com/daviddrysdale/python-phonenumbers/blob/9cc5bb4ab5e661e70789b4c64bf7a9383c7bdc20/python/phonenumbers/shortnumberinfo.py#L295-L322
train
Shopify/shopify_python_api
shopify/base.py
ShopifyResourceMeta.connection
def connection(cls): """HTTP connection for the current thread""" local = cls._threadlocal if not getattr(local, 'connection', None): # Make sure these variables are no longer affected by other threads. local.user = cls.user local.password = cls.password ...
python
def connection(cls): """HTTP connection for the current thread""" local = cls._threadlocal if not getattr(local, 'connection', None): # Make sure these variables are no longer affected by other threads. local.user = cls.user local.password = cls.password ...
[ "def", "connection", "(", "cls", ")", ":", "local", "=", "cls", ".", "_threadlocal", "if", "not", "getattr", "(", "local", ",", "'connection'", ",", "None", ")", ":", "local", ".", "user", "=", "cls", ".", "user", "local", ".", "password", "=", "cls"...
HTTP connection for the current thread
[ "HTTP", "connection", "for", "the", "current", "thread" ]
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/shopify/base.py#L33-L50
train
Shopify/shopify_python_api
shopify/base.py
ShopifyResourceMeta.get_prefix_source
def get_prefix_source(cls): """Return the prefix source, by default derived from site.""" try: return cls.override_prefix() except AttributeError: if hasattr(cls, '_prefix_source'): return cls.site + cls._prefix_source else: ret...
python
def get_prefix_source(cls): """Return the prefix source, by default derived from site.""" try: return cls.override_prefix() except AttributeError: if hasattr(cls, '_prefix_source'): return cls.site + cls._prefix_source else: ret...
[ "def", "get_prefix_source", "(", "cls", ")", ":", "try", ":", "return", "cls", ".", "override_prefix", "(", ")", "except", "AttributeError", ":", "if", "hasattr", "(", "cls", ",", "'_prefix_source'", ")", ":", "return", "cls", ".", "site", "+", "cls", "....
Return the prefix source, by default derived from site.
[ "Return", "the", "prefix", "source", "by", "default", "derived", "from", "site", "." ]
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/shopify/base.py#L119-L127
train
Shopify/shopify_python_api
shopify/session.py
Session.__encoded_params_for_signature
def __encoded_params_for_signature(cls, params): """ Sort and combine query parameters into a single string, excluding those that should be removed and joining with '&' """ def encoded_pairs(params): for k, v in six.iteritems(params): if k == 'hmac': ...
python
def __encoded_params_for_signature(cls, params): """ Sort and combine query parameters into a single string, excluding those that should be removed and joining with '&' """ def encoded_pairs(params): for k, v in six.iteritems(params): if k == 'hmac': ...
[ "def", "__encoded_params_for_signature", "(", "cls", ",", "params", ")", ":", "def", "encoded_pairs", "(", "params", ")", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "params", ")", ":", "if", "k", "==", "'hmac'", ":", "continue", "if...
Sort and combine query parameters into a single string, excluding those that should be removed and joining with '&'
[ "Sort", "and", "combine", "query", "parameters", "into", "a", "single", "string", "excluding", "those", "that", "should", "be", "removed", "and", "joining", "with", "&" ]
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/shopify/session.py#L141-L160
train
Shopify/shopify_python_api
shopify/resources/refund.py
Refund.calculate
def calculate(cls, order_id, shipping=None, refund_line_items=None): """ Calculates refund transactions based on line items and shipping. When you want to create a refund, you should first use the calculate endpoint to generate accurate refund transactions. Args: orde...
python
def calculate(cls, order_id, shipping=None, refund_line_items=None): """ Calculates refund transactions based on line items and shipping. When you want to create a refund, you should first use the calculate endpoint to generate accurate refund transactions. Args: orde...
[ "def", "calculate", "(", "cls", ",", "order_id", ",", "shipping", "=", "None", ",", "refund_line_items", "=", "None", ")", ":", "data", "=", "{", "}", "if", "shipping", ":", "data", "[", "'shipping'", "]", "=", "shipping", "data", "[", "'refund_line_item...
Calculates refund transactions based on line items and shipping. When you want to create a refund, you should first use the calculate endpoint to generate accurate refund transactions. Args: order_id: Order ID for which the Refund has to created. shipping: Specify how much...
[ "Calculates", "refund", "transactions", "based", "on", "line", "items", "and", "shipping", ".", "When", "you", "want", "to", "create", "a", "refund", "you", "should", "first", "use", "the", "calculate", "endpoint", "to", "generate", "accurate", "refund", "tran...
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/shopify/resources/refund.py#L10-L34
train
Shopify/shopify_python_api
scripts/shopify_api.py
TasksMeta.help
def help(cls, task=None): """Describe available tasks or one specific task""" if task is None: usage_list = [] for task in iter(cls._tasks): task_func = getattr(cls, task) usage_string = " %s %s" % (cls._prog, task_func.usage) desc...
python
def help(cls, task=None): """Describe available tasks or one specific task""" if task is None: usage_list = [] for task in iter(cls._tasks): task_func = getattr(cls, task) usage_string = " %s %s" % (cls._prog, task_func.usage) desc...
[ "def", "help", "(", "cls", ",", "task", "=", "None", ")", ":", "if", "task", "is", "None", ":", "usage_list", "=", "[", "]", "for", "task", "in", "iter", "(", "cls", ".", "_tasks", ")", ":", "task_func", "=", "getattr", "(", "cls", ",", "task", ...
Describe available tasks or one specific task
[ "Describe", "available", "tasks", "or", "one", "specific", "task" ]
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/scripts/shopify_api.py#L62-L86
train
Shopify/shopify_python_api
shopify/resources/gift_card.py
GiftCard.add_adjustment
def add_adjustment(self, adjustment): """ Create a new Gift Card Adjustment """ resource = self.post("adjustments", adjustment.encode()) return GiftCardAdjustment(GiftCard.format.decode(resource.body))
python
def add_adjustment(self, adjustment): """ Create a new Gift Card Adjustment """ resource = self.post("adjustments", adjustment.encode()) return GiftCardAdjustment(GiftCard.format.decode(resource.body))
[ "def", "add_adjustment", "(", "self", ",", "adjustment", ")", ":", "resource", "=", "self", ".", "post", "(", "\"adjustments\"", ",", "adjustment", ".", "encode", "(", ")", ")", "return", "GiftCardAdjustment", "(", "GiftCard", ".", "format", ".", "decode", ...
Create a new Gift Card Adjustment
[ "Create", "a", "new", "Gift", "Card", "Adjustment" ]
88d3ba332fb2cd331f87517a16f2c2d4296cee90
https://github.com/Shopify/shopify_python_api/blob/88d3ba332fb2cd331f87517a16f2c2d4296cee90/shopify/resources/gift_card.py#L26-L31
train
aiven/pghoard
pghoard/rohmu/object_storage/local.py
atomic_create_file
def atomic_create_file(file_path): """Open a temporary file for writing, rename to final name when done""" fd, tmp_file_path = tempfile.mkstemp( prefix=os.path.basename(file_path), dir=os.path.dirname(file_path), suffix=".metadata_tmp" ) try: with os.fdopen(fd, "w") as out_file: ...
python
def atomic_create_file(file_path): """Open a temporary file for writing, rename to final name when done""" fd, tmp_file_path = tempfile.mkstemp( prefix=os.path.basename(file_path), dir=os.path.dirname(file_path), suffix=".metadata_tmp" ) try: with os.fdopen(fd, "w") as out_file: ...
[ "def", "atomic_create_file", "(", "file_path", ")", ":", "fd", ",", "tmp_file_path", "=", "tempfile", ".", "mkstemp", "(", "prefix", "=", "os", ".", "path", ".", "basename", "(", "file_path", ")", ",", "dir", "=", "os", ".", "path", ".", "dirname", "("...
Open a temporary file for writing, rename to final name when done
[ "Open", "a", "temporary", "file", "for", "writing", "rename", "to", "final", "name", "when", "done" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/local.py#L217-L230
train
aiven/pghoard
pghoard/rohmu/object_storage/azure.py
AzureTransfer._stream_blob
def _stream_blob(self, key, fileobj, progress_callback): """Streams contents of given key to given fileobj. Data is read sequentially in chunks without any seeks. This requires duplicating some functionality of the Azure SDK, which only allows reading entire blob into memory at once or returning...
python
def _stream_blob(self, key, fileobj, progress_callback): """Streams contents of given key to given fileobj. Data is read sequentially in chunks without any seeks. This requires duplicating some functionality of the Azure SDK, which only allows reading entire blob into memory at once or returning...
[ "def", "_stream_blob", "(", "self", ",", "key", ",", "fileobj", ",", "progress_callback", ")", ":", "file_size", "=", "None", "start_range", "=", "0", "chunk_size", "=", "self", ".", "conn", ".", "MAX_CHUNK_GET_SIZE", "end_range", "=", "chunk_size", "-", "1"...
Streams contents of given key to given fileobj. Data is read sequentially in chunks without any seeks. This requires duplicating some functionality of the Azure SDK, which only allows reading entire blob into memory at once or returning data from random offsets
[ "Streams", "contents", "of", "given", "key", "to", "given", "fileobj", ".", "Data", "is", "read", "sequentially", "in", "chunks", "without", "any", "seeks", ".", "This", "requires", "duplicating", "some", "functionality", "of", "the", "Azure", "SDK", "which", ...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/azure.py#L161-L191
train
aiven/pghoard
pghoard/rohmu/object_storage/base.py
BaseTransfer.format_key_for_backend
def format_key_for_backend(self, key, remove_slash_prefix=False, trailing_slash=False): """Add a possible prefix to the key before sending it to the backend""" path = self.prefix + key if trailing_slash: if not path or path[-1] != "/": path += "/" else: ...
python
def format_key_for_backend(self, key, remove_slash_prefix=False, trailing_slash=False): """Add a possible prefix to the key before sending it to the backend""" path = self.prefix + key if trailing_slash: if not path or path[-1] != "/": path += "/" else: ...
[ "def", "format_key_for_backend", "(", "self", ",", "key", ",", "remove_slash_prefix", "=", "False", ",", "trailing_slash", "=", "False", ")", ":", "path", "=", "self", ".", "prefix", "+", "key", "if", "trailing_slash", ":", "if", "not", "path", "or", "path...
Add a possible prefix to the key before sending it to the backend
[ "Add", "a", "possible", "prefix", "to", "the", "key", "before", "sending", "it", "to", "the", "backend" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/base.py#L34-L44
train
aiven/pghoard
pghoard/rohmu/object_storage/base.py
BaseTransfer.format_key_from_backend
def format_key_from_backend(self, key): """Strip the configured prefix from a key retrieved from the backend before passing it on to other pghoard code and presenting it to the user.""" if not self.prefix: return key if not key.startswith(self.prefix): rai...
python
def format_key_from_backend(self, key): """Strip the configured prefix from a key retrieved from the backend before passing it on to other pghoard code and presenting it to the user.""" if not self.prefix: return key if not key.startswith(self.prefix): rai...
[ "def", "format_key_from_backend", "(", "self", ",", "key", ")", ":", "if", "not", "self", ".", "prefix", ":", "return", "key", "if", "not", "key", ".", "startswith", "(", "self", ".", "prefix", ")", ":", "raise", "StorageError", "(", "\"Key {!r} does not s...
Strip the configured prefix from a key retrieved from the backend before passing it on to other pghoard code and presenting it to the user.
[ "Strip", "the", "configured", "prefix", "from", "a", "key", "retrieved", "from", "the", "backend", "before", "passing", "it", "on", "to", "other", "pghoard", "code", "and", "presenting", "it", "to", "the", "user", "." ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/base.py#L46-L54
train
aiven/pghoard
pghoard/rohmu/object_storage/base.py
BaseTransfer.delete_tree
def delete_tree(self, key): """Delete all keys under given root key. Basic implementation works by just listing all available keys and deleting them individually but storage providers can implement more efficient logic.""" self.log.debug("Deleting tree: %r", key) names = [item["name"] fo...
python
def delete_tree(self, key): """Delete all keys under given root key. Basic implementation works by just listing all available keys and deleting them individually but storage providers can implement more efficient logic.""" self.log.debug("Deleting tree: %r", key) names = [item["name"] fo...
[ "def", "delete_tree", "(", "self", ",", "key", ")", ":", "self", ".", "log", ".", "debug", "(", "\"Deleting tree: %r\"", ",", "key", ")", "names", "=", "[", "item", "[", "\"name\"", "]", "for", "item", "in", "self", ".", "list_path", "(", "key", ",",...
Delete all keys under given root key. Basic implementation works by just listing all available keys and deleting them individually but storage providers can implement more efficient logic.
[ "Delete", "all", "keys", "under", "given", "root", "key", ".", "Basic", "implementation", "works", "by", "just", "listing", "all", "available", "keys", "and", "deleting", "them", "individually", "but", "storage", "providers", "can", "implement", "more", "efficie...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/base.py#L59-L65
train
aiven/pghoard
pghoard/rohmu/object_storage/base.py
BaseTransfer.sanitize_metadata
def sanitize_metadata(self, metadata, replace_hyphen_with="-"): """Convert non-string metadata values to strings and drop null values""" return {str(k).replace("-", replace_hyphen_with): str(v) for k, v in (metadata or {}).items() if v is not None}
python
def sanitize_metadata(self, metadata, replace_hyphen_with="-"): """Convert non-string metadata values to strings and drop null values""" return {str(k).replace("-", replace_hyphen_with): str(v) for k, v in (metadata or {}).items() if v is not None}
[ "def", "sanitize_metadata", "(", "self", ",", "metadata", ",", "replace_hyphen_with", "=", "\"-\"", ")", ":", "return", "{", "str", "(", "k", ")", ".", "replace", "(", "\"-\"", ",", "replace_hyphen_with", ")", ":", "str", "(", "v", ")", "for", "k", ","...
Convert non-string metadata values to strings and drop null values
[ "Convert", "non", "-", "string", "metadata", "values", "to", "strings", "and", "drop", "null", "values" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/base.py#L112-L115
train
aiven/pghoard
pghoard/rohmu/dates.py
parse_timestamp
def parse_timestamp(ts, *, with_tz=True, assume_local=False): """Parse a given timestamp and return a datetime object with or without tzinfo. If `with_tz` is False and we can't parse a timezone from the timestamp the datetime object is returned as-is and we assume the timezone is whatever was requested. I...
python
def parse_timestamp(ts, *, with_tz=True, assume_local=False): """Parse a given timestamp and return a datetime object with or without tzinfo. If `with_tz` is False and we can't parse a timezone from the timestamp the datetime object is returned as-is and we assume the timezone is whatever was requested. I...
[ "def", "parse_timestamp", "(", "ts", ",", "*", ",", "with_tz", "=", "True", ",", "assume_local", "=", "False", ")", ":", "parse_result", "=", "dateutil", ".", "parser", ".", "parse", "(", "ts", ")", "dt", "=", "parse_result", "[", "0", "]", "if", "is...
Parse a given timestamp and return a datetime object with or without tzinfo. If `with_tz` is False and we can't parse a timezone from the timestamp the datetime object is returned as-is and we assume the timezone is whatever was requested. If `with_tz` is False and we can parse a timezone, the timestamp i...
[ "Parse", "a", "given", "timestamp", "and", "return", "a", "datetime", "object", "with", "or", "without", "tzinfo", "." ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/dates.py#L12-L40
train
aiven/pghoard
pghoard/common.py
create_pgpass_file
def create_pgpass_file(connection_string_or_info): """Look up password from the given object which can be a dict or a string and write a possible password in a pgpass file; returns a connection_string without a password in it""" info = pgutil.get_connection_info(connection_string_or_info) if "passwo...
python
def create_pgpass_file(connection_string_or_info): """Look up password from the given object which can be a dict or a string and write a possible password in a pgpass file; returns a connection_string without a password in it""" info = pgutil.get_connection_info(connection_string_or_info) if "passwo...
[ "def", "create_pgpass_file", "(", "connection_string_or_info", ")", ":", "info", "=", "pgutil", ".", "get_connection_info", "(", "connection_string_or_info", ")", "if", "\"password\"", "not", "in", "info", ":", "return", "pgutil", ".", "create_connection_string", "(",...
Look up password from the given object which can be a dict or a string and write a possible password in a pgpass file; returns a connection_string without a password in it
[ "Look", "up", "password", "from", "the", "given", "object", "which", "can", "be", "a", "dict", "or", "a", "string", "and", "write", "a", "possible", "password", "in", "a", "pgpass", "file", ";", "returns", "a", "connection_string", "without", "a", "passwor...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/common.py#L26-L55
train
aiven/pghoard
pghoard/common.py
replication_connection_string_and_slot_using_pgpass
def replication_connection_string_and_slot_using_pgpass(target_node_info): """Like `connection_string_and_slot_using_pgpass` but returns a connection string for a replication connection.""" connection_info, slot = connection_info_and_slot(target_node_info) connection_info["dbname"] = "replication" c...
python
def replication_connection_string_and_slot_using_pgpass(target_node_info): """Like `connection_string_and_slot_using_pgpass` but returns a connection string for a replication connection.""" connection_info, slot = connection_info_and_slot(target_node_info) connection_info["dbname"] = "replication" c...
[ "def", "replication_connection_string_and_slot_using_pgpass", "(", "target_node_info", ")", ":", "connection_info", ",", "slot", "=", "connection_info_and_slot", "(", "target_node_info", ")", "connection_info", "[", "\"dbname\"", "]", "=", "\"replication\"", "connection_info"...
Like `connection_string_and_slot_using_pgpass` but returns a connection string for a replication connection.
[ "Like", "connection_string_and_slot_using_pgpass", "but", "returns", "a", "connection", "string", "for", "a", "replication", "connection", "." ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/common.py#L85-L92
train
aiven/pghoard
pghoard/transfer.py
TransferAgent.transmit_metrics
def transmit_metrics(self): """ Keep metrics updated about how long time ago each filetype was successfully uploaded. Transmits max once per ten seconds, regardless of how many threads are running. """ global _last_stats_transmit_time # pylint: disable=global-statement w...
python
def transmit_metrics(self): """ Keep metrics updated about how long time ago each filetype was successfully uploaded. Transmits max once per ten seconds, regardless of how many threads are running. """ global _last_stats_transmit_time # pylint: disable=global-statement w...
[ "def", "transmit_metrics", "(", "self", ")", ":", "global", "_last_stats_transmit_time", "with", "_STATS_LOCK", ":", "if", "time", ".", "monotonic", "(", ")", "-", "_last_stats_transmit_time", "<", "10.0", ":", "return", "for", "site", "in", "self", ".", "stat...
Keep metrics updated about how long time ago each filetype was successfully uploaded. Transmits max once per ten seconds, regardless of how many threads are running.
[ "Keep", "metrics", "updated", "about", "how", "long", "time", "ago", "each", "filetype", "was", "successfully", "uploaded", ".", "Transmits", "max", "once", "per", "ten", "seconds", "regardless", "of", "how", "many", "threads", "are", "running", "." ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/transfer.py#L80-L101
train
aiven/pghoard
pghoard/rohmu/encryptor.py
EncryptorFile.write
def write(self, data): """Encrypt and write the given bytes""" self._check_not_closed() if not data: return 0 enc_data = self.encryptor.update(data) self.next_fp.write(enc_data) self.offset += len(data) return len(data)
python
def write(self, data): """Encrypt and write the given bytes""" self._check_not_closed() if not data: return 0 enc_data = self.encryptor.update(data) self.next_fp.write(enc_data) self.offset += len(data) return len(data)
[ "def", "write", "(", "self", ",", "data", ")", ":", "self", ".", "_check_not_closed", "(", ")", "if", "not", "data", ":", "return", "0", "enc_data", "=", "self", ".", "encryptor", ".", "update", "(", "data", ")", "self", ".", "next_fp", ".", "write",...
Encrypt and write the given bytes
[ "Encrypt", "and", "write", "the", "given", "bytes" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/encryptor.py#L101-L109
train
aiven/pghoard
pghoard/rohmu/encryptor.py
DecryptorFile.read
def read(self, size=-1): """Read up to size decrypted bytes""" self._check_not_closed() if self.state == "EOF" or size == 0: return b"" elif size < 0: return self._read_all() else: return self._read_block(size)
python
def read(self, size=-1): """Read up to size decrypted bytes""" self._check_not_closed() if self.state == "EOF" or size == 0: return b"" elif size < 0: return self._read_all() else: return self._read_block(size)
[ "def", "read", "(", "self", ",", "size", "=", "-", "1", ")", ":", "self", ".", "_check_not_closed", "(", ")", "if", "self", ".", "state", "==", "\"EOF\"", "or", "size", "==", "0", ":", "return", "b\"\"", "elif", "size", "<", "0", ":", "return", "...
Read up to size decrypted bytes
[ "Read", "up", "to", "size", "decrypted", "bytes" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/encryptor.py#L314-L322
train
aiven/pghoard
pghoard/gnutaremu.py
SedStatementParser.tokenize_string
def tokenize_string(cls, string, separator): """Split string with given separator unless the separator is escaped with backslash""" results = [] token = "" found_escape = False for c in string: if found_escape: if c == separator: to...
python
def tokenize_string(cls, string, separator): """Split string with given separator unless the separator is escaped with backslash""" results = [] token = "" found_escape = False for c in string: if found_escape: if c == separator: to...
[ "def", "tokenize_string", "(", "cls", ",", "string", ",", "separator", ")", ":", "results", "=", "[", "]", "token", "=", "\"\"", "found_escape", "=", "False", "for", "c", "in", "string", ":", "if", "found_escape", ":", "if", "c", "==", "separator", ":"...
Split string with given separator unless the separator is escaped with backslash
[ "Split", "string", "with", "given", "separator", "unless", "the", "separator", "is", "escaped", "with", "backslash" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/gnutaremu.py#L148-L170
train
aiven/pghoard
pghoard/rohmu/object_storage/google.py
GoogleTransfer._unpaginate
def _unpaginate(self, domain, initial_op, *, on_properties): """Iterate thru the request pages until all items have been processed""" request = initial_op(domain) while request is not None: result = self._retry_on_reset(request, request.execute) for on_property in on_prop...
python
def _unpaginate(self, domain, initial_op, *, on_properties): """Iterate thru the request pages until all items have been processed""" request = initial_op(domain) while request is not None: result = self._retry_on_reset(request, request.execute) for on_property in on_prop...
[ "def", "_unpaginate", "(", "self", ",", "domain", ",", "initial_op", ",", "*", ",", "on_properties", ")", ":", "request", "=", "initial_op", "(", "domain", ")", "while", "request", "is", "not", "None", ":", "result", "=", "self", ".", "_retry_on_reset", ...
Iterate thru the request pages until all items have been processed
[ "Iterate", "thru", "the", "request", "pages", "until", "all", "items", "have", "been", "processed" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/google.py#L194-L203
train
aiven/pghoard
pghoard/rohmu/object_storage/google.py
GoogleTransfer.get_or_create_bucket
def get_or_create_bucket(self, bucket_name): """Look up the bucket if it already exists and try to create the bucket in case it doesn't. Note that we can't just always try to unconditionally create the bucket as Google imposes a strict rate limit on bucket creation operations, even if i...
python
def get_or_create_bucket(self, bucket_name): """Look up the bucket if it already exists and try to create the bucket in case it doesn't. Note that we can't just always try to unconditionally create the bucket as Google imposes a strict rate limit on bucket creation operations, even if i...
[ "def", "get_or_create_bucket", "(", "self", ",", "bucket_name", ")", ":", "start_time", "=", "time", ".", "time", "(", ")", "gs_buckets", "=", "self", ".", "gs", ".", "buckets", "(", ")", "try", ":", "request", "=", "gs_buckets", ".", "get", "(", "buck...
Look up the bucket if it already exists and try to create the bucket in case it doesn't. Note that we can't just always try to unconditionally create the bucket as Google imposes a strict rate limit on bucket creation operations, even if it doesn't result in a new bucket. Quiet...
[ "Look", "up", "the", "bucket", "if", "it", "already", "exists", "and", "try", "to", "create", "the", "bucket", "in", "case", "it", "doesn", "t", ".", "Note", "that", "we", "can", "t", "just", "always", "try", "to", "unconditionally", "create", "the", "...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/rohmu/object_storage/google.py#L348-L390
train
aiven/pghoard
pghoard/walreceiver.py
WALReceiver.fetch_timeline_history_files
def fetch_timeline_history_files(self, max_timeline): """Copy all timeline history files found on the server without checking if we have them or not. The history files are very small so reuploading them should not matter.""" while max_timeline > 1: self.c.execute("TIMEL...
python
def fetch_timeline_history_files(self, max_timeline): """Copy all timeline history files found on the server without checking if we have them or not. The history files are very small so reuploading them should not matter.""" while max_timeline > 1: self.c.execute("TIMEL...
[ "def", "fetch_timeline_history_files", "(", "self", ",", "max_timeline", ")", ":", "while", "max_timeline", ">", "1", ":", "self", ".", "c", ".", "execute", "(", "\"TIMELINE_HISTORY {}\"", ".", "format", "(", "max_timeline", ")", ")", "timeline_history", "=", ...
Copy all timeline history files found on the server without checking if we have them or not. The history files are very small so reuploading them should not matter.
[ "Copy", "all", "timeline", "history", "files", "found", "on", "the", "server", "without", "checking", "if", "we", "have", "them", "or", "not", ".", "The", "history", "files", "are", "very", "small", "so", "reuploading", "them", "should", "not", "matter", "...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/walreceiver.py#L60-L81
train
aiven/pghoard
pghoard/pghoard.py
PGHoard.check_backup_count_and_state
def check_backup_count_and_state(self, site): """Look up basebackups from the object store, prune any extra backups and return the datetime of the latest backup.""" basebackups = self.get_remote_basebackups_info(site) self.log.debug("Found %r basebackups", basebackups) if baseba...
python
def check_backup_count_and_state(self, site): """Look up basebackups from the object store, prune any extra backups and return the datetime of the latest backup.""" basebackups = self.get_remote_basebackups_info(site) self.log.debug("Found %r basebackups", basebackups) if baseba...
[ "def", "check_backup_count_and_state", "(", "self", ",", "site", ")", ":", "basebackups", "=", "self", ".", "get_remote_basebackups_info", "(", "site", ")", "self", ".", "log", ".", "debug", "(", "\"Found %r basebackups\"", ",", "basebackups", ")", "if", "baseba...
Look up basebackups from the object store, prune any extra backups and return the datetime of the latest backup.
[ "Look", "up", "basebackups", "from", "the", "object", "store", "prune", "any", "extra", "backups", "and", "return", "the", "datetime", "of", "the", "latest", "backup", "." ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/pghoard.py#L311-L340
train
aiven/pghoard
pghoard/pghoard.py
PGHoard.startup_walk_for_missed_files
def startup_walk_for_missed_files(self): """Check xlog and xlog_incoming directories for files that receivexlog has received but not yet compressed as well as the files we have compressed but not yet uploaded and process them.""" for site in self.config["backup_sites"]: compressed_xl...
python
def startup_walk_for_missed_files(self): """Check xlog and xlog_incoming directories for files that receivexlog has received but not yet compressed as well as the files we have compressed but not yet uploaded and process them.""" for site in self.config["backup_sites"]: compressed_xl...
[ "def", "startup_walk_for_missed_files", "(", "self", ")", ":", "for", "site", "in", "self", ".", "config", "[", "\"backup_sites\"", "]", ":", "compressed_xlog_path", ",", "_", "=", "self", ".", "create_backup_site_paths", "(", "site", ")", "uncompressed_xlog_path"...
Check xlog and xlog_incoming directories for files that receivexlog has received but not yet compressed as well as the files we have compressed but not yet uploaded and process them.
[ "Check", "xlog", "and", "xlog_incoming", "directories", "for", "files", "that", "receivexlog", "has", "received", "but", "not", "yet", "compressed", "as", "well", "as", "the", "files", "we", "have", "compressed", "but", "not", "yet", "uploaded", "and", "proces...
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/pghoard.py#L346-L392
train
aiven/pghoard
pghoard/pghoard.py
PGHoard.write_backup_state_to_json_file
def write_backup_state_to_json_file(self): """Periodically write a JSON state file to disk""" start_time = time.time() state_file_path = self.config["json_state_file_path"] self.state["walreceivers"] = { key: {"latest_activity": value.latest_activity, "running": value.running...
python
def write_backup_state_to_json_file(self): """Periodically write a JSON state file to disk""" start_time = time.time() state_file_path = self.config["json_state_file_path"] self.state["walreceivers"] = { key: {"latest_activity": value.latest_activity, "running": value.running...
[ "def", "write_backup_state_to_json_file", "(", "self", ")", ":", "start_time", "=", "time", ".", "time", "(", ")", "state_file_path", "=", "self", ".", "config", "[", "\"json_state_file_path\"", "]", "self", ".", "state", "[", "\"walreceivers\"", "]", "=", "{"...
Periodically write a JSON state file to disk
[ "Periodically", "write", "a", "JSON", "state", "file", "to", "disk" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/pghoard.py#L493-L518
train
aiven/pghoard
pghoard/pgutil.py
get_connection_info
def get_connection_info(info): """turn a connection info object into a dict or return it if it was a dict already. supports both the traditional libpq format and the new url format""" if isinstance(info, dict): return info.copy() elif info.startswith("postgres://") or info.startswith("postg...
python
def get_connection_info(info): """turn a connection info object into a dict or return it if it was a dict already. supports both the traditional libpq format and the new url format""" if isinstance(info, dict): return info.copy() elif info.startswith("postgres://") or info.startswith("postg...
[ "def", "get_connection_info", "(", "info", ")", ":", "if", "isinstance", "(", "info", ",", "dict", ")", ":", "return", "info", ".", "copy", "(", ")", "elif", "info", ".", "startswith", "(", "\"postgres://\"", ")", "or", "info", ".", "startswith", "(", ...
turn a connection info object into a dict or return it if it was a dict already. supports both the traditional libpq format and the new url format
[ "turn", "a", "connection", "info", "object", "into", "a", "dict", "or", "return", "it", "if", "it", "was", "a", "dict", "already", ".", "supports", "both", "the", "traditional", "libpq", "format", "and", "the", "new", "url", "format" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/pgutil.py#L34-L43
train
aiven/pghoard
pghoard/restore.py
Restore.list_basebackups_http
def list_basebackups_http(self, arg): """List available basebackups from a HTTP source""" self.storage = HTTPRestore(arg.host, arg.port, arg.site) self.storage.show_basebackup_list(verbose=arg.verbose)
python
def list_basebackups_http(self, arg): """List available basebackups from a HTTP source""" self.storage = HTTPRestore(arg.host, arg.port, arg.site) self.storage.show_basebackup_list(verbose=arg.verbose)
[ "def", "list_basebackups_http", "(", "self", ",", "arg", ")", ":", "self", ".", "storage", "=", "HTTPRestore", "(", "arg", ".", "host", ",", "arg", ".", "port", ",", "arg", ".", "site", ")", "self", ".", "storage", ".", "show_basebackup_list", "(", "ve...
List available basebackups from a HTTP source
[ "List", "available", "basebackups", "from", "a", "HTTP", "source" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/restore.py#L184-L187
train
aiven/pghoard
pghoard/restore.py
Restore.list_basebackups
def list_basebackups(self, arg): """List basebackups from an object store""" self.config = config.read_json_config_file(arg.config, check_commands=False, check_pgdata=False) site = config.get_site_from_config(self.config, arg.site) self.storage = self._get_object_storage(site, pgdata=Non...
python
def list_basebackups(self, arg): """List basebackups from an object store""" self.config = config.read_json_config_file(arg.config, check_commands=False, check_pgdata=False) site = config.get_site_from_config(self.config, arg.site) self.storage = self._get_object_storage(site, pgdata=Non...
[ "def", "list_basebackups", "(", "self", ",", "arg", ")", ":", "self", ".", "config", "=", "config", ".", "read_json_config_file", "(", "arg", ".", "config", ",", "check_commands", "=", "False", ",", "check_pgdata", "=", "False", ")", "site", "=", "config",...
List basebackups from an object store
[ "List", "basebackups", "from", "an", "object", "store" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/restore.py#L194-L199
train
aiven/pghoard
pghoard/restore.py
Restore.get_basebackup
def get_basebackup(self, arg): """Download a basebackup from an object store""" if not arg.tablespace_dir: tablespace_mapping = {} else: try: tablespace_mapping = dict(v.split("=", 1) for v in arg.tablespace_dir) except ValueError: ...
python
def get_basebackup(self, arg): """Download a basebackup from an object store""" if not arg.tablespace_dir: tablespace_mapping = {} else: try: tablespace_mapping = dict(v.split("=", 1) for v in arg.tablespace_dir) except ValueError: ...
[ "def", "get_basebackup", "(", "self", ",", "arg", ")", ":", "if", "not", "arg", ".", "tablespace_dir", ":", "tablespace_mapping", "=", "{", "}", "else", ":", "try", ":", "tablespace_mapping", "=", "dict", "(", "v", ".", "split", "(", "\"=\"", ",", "1",...
Download a basebackup from an object store
[ "Download", "a", "basebackup", "from", "an", "object", "store" ]
2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/restore.py#L201-L238
train
scikit-hep/uproot
uproot/rootio.py
TKey.get
def get(self, dismiss=True): """Extract the object this key points to. Objects are not read or decompressed until this function is explicitly called. """ try: return _classof(self._context, self._fClassName).read(self._source, self._cursor.copied(), self._context, self) ...
python
def get(self, dismiss=True): """Extract the object this key points to. Objects are not read or decompressed until this function is explicitly called. """ try: return _classof(self._context, self._fClassName).read(self._source, self._cursor.copied(), self._context, self) ...
[ "def", "get", "(", "self", ",", "dismiss", "=", "True", ")", ":", "try", ":", "return", "_classof", "(", "self", ".", "_context", ",", "self", ".", "_fClassName", ")", ".", "read", "(", "self", ".", "_source", ",", "self", ".", "_cursor", ".", "cop...
Extract the object this key points to. Objects are not read or decompressed until this function is explicitly called.
[ "Extract", "the", "object", "this", "key", "points", "to", "." ]
fc406827e36ed87cfb1062806e118f53fd3a3b0a
https://github.com/scikit-hep/uproot/blob/fc406827e36ed87cfb1062806e118f53fd3a3b0a/uproot/rootio.py#L883-L893
train
zarr-developers/zarr
zarr/hierarchy.py
open_group
def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=None, chunk_store=None): """Open a group using file-mode-like semantics. Parameters ---------- store : MutableMapping or string, optional Store or path to directory in file system or name of zip file. ...
python
def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=None, chunk_store=None): """Open a group using file-mode-like semantics. Parameters ---------- store : MutableMapping or string, optional Store or path to directory in file system or name of zip file. ...
[ "def", "open_group", "(", "store", "=", "None", ",", "mode", "=", "'a'", ",", "cache_attrs", "=", "True", ",", "synchronizer", "=", "None", ",", "path", "=", "None", ",", "chunk_store", "=", "None", ")", ":", "store", "=", "_normalize_store_arg", "(", ...
Open a group using file-mode-like semantics. Parameters ---------- store : MutableMapping or string, optional Store or path to directory in file system or name of zip file. mode : {'r', 'r+', 'a', 'w', 'w-'}, optional Persistence mode: 'r' means read only (must exist); 'r+' means ...
[ "Open", "a", "group", "using", "file", "-", "mode", "-", "like", "semantics", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L1060-L1139
train
zarr-developers/zarr
zarr/hierarchy.py
Group.name
def name(self): """Group name following h5py convention.""" if self._path: # follow h5py convention: add leading slash name = self._path if name[0] != '/': name = '/' + name return name return '/'
python
def name(self): """Group name following h5py convention.""" if self._path: # follow h5py convention: add leading slash name = self._path if name[0] != '/': name = '/' + name return name return '/'
[ "def", "name", "(", "self", ")", ":", "if", "self", ".", "_path", ":", "name", "=", "self", ".", "_path", "if", "name", "[", "0", "]", "!=", "'/'", ":", "name", "=", "'/'", "+", "name", "return", "name", "return", "'/'" ]
Group name following h5py convention.
[ "Group", "name", "following", "h5py", "convention", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L136-L144
train
zarr-developers/zarr
zarr/hierarchy.py
Group.group_keys
def group_keys(self): """Return an iterator over member names for groups only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) ...
python
def group_keys(self): """Return an iterator over member names for groups only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) ...
[ "def", "group_keys", "(", "self", ")", ":", "for", "key", "in", "sorted", "(", "listdir", "(", "self", ".", "_store", ",", "self", ".", "_path", ")", ")", ":", "path", "=", "self", ".", "_key_prefix", "+", "key", "if", "contains_group", "(", "self", ...
Return an iterator over member names for groups only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) >>> d2 = g1.create_datase...
[ "Return", "an", "iterator", "over", "member", "names", "for", "groups", "only", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L368-L386
train
zarr-developers/zarr
zarr/hierarchy.py
Group.array_keys
def array_keys(self): """Return an iterator over member names for arrays only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) ...
python
def array_keys(self): """Return an iterator over member names for arrays only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) ...
[ "def", "array_keys", "(", "self", ")", ":", "for", "key", "in", "sorted", "(", "listdir", "(", "self", ".", "_store", ",", "self", ".", "_path", ")", ")", ":", "path", "=", "self", ".", "_key_prefix", "+", "key", "if", "contains_array", "(", "self", ...
Return an iterator over member names for arrays only. Examples -------- >>> import zarr >>> g1 = zarr.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) >>> d2 = g1.create_datase...
[ "Return", "an", "iterator", "over", "member", "names", "for", "arrays", "only", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L413-L431
train
zarr-developers/zarr
zarr/hierarchy.py
Group.visitvalues
def visitvalues(self, func): """Run ``func`` on each object. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr ...
python
def visitvalues(self, func): """Run ``func`` on each object. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr ...
[ "def", "visitvalues", "(", "self", ",", "func", ")", ":", "def", "_visit", "(", "obj", ")", ":", "yield", "obj", "keys", "=", "sorted", "(", "getattr", "(", "obj", ",", "\"keys\"", ",", "lambda", ":", "[", "]", ")", "(", ")", ")", "for", "k", "...
Run ``func`` on each object. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr >>> g1 = zarr.group() >>...
[ "Run", "func", "on", "each", "object", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L458-L496
train
zarr-developers/zarr
zarr/hierarchy.py
Group.visit
def visit(self, func): """Run ``func`` on each object's path. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr...
python
def visit(self, func): """Run ``func`` on each object's path. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr...
[ "def", "visit", "(", "self", ",", "func", ")", ":", "base_len", "=", "len", "(", "self", ".", "name", ")", "return", "self", ".", "visitvalues", "(", "lambda", "o", ":", "func", "(", "o", ".", "name", "[", "base_len", ":", "]", ".", "lstrip", "("...
Run ``func`` on each object's path. Note: If ``func`` returns ``None`` (or doesn't return), iteration continues. However, if ``func`` returns anything else, it ceases and returns that value. Examples -------- >>> import zarr >>> g1 = zarr.group() ...
[ "Run", "func", "on", "each", "object", "s", "path", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L498-L527
train
zarr-developers/zarr
zarr/hierarchy.py
Group.tree
def tree(self, expand=False, level=None): """Provide a ``print``-able display of the hierarchy. Parameters ---------- expand : bool, optional Only relevant for HTML representation. If True, tree will be fully expanded. level : int, optional Maximum depth ...
python
def tree(self, expand=False, level=None): """Provide a ``print``-able display of the hierarchy. Parameters ---------- expand : bool, optional Only relevant for HTML representation. If True, tree will be fully expanded. level : int, optional Maximum depth ...
[ "def", "tree", "(", "self", ",", "expand", "=", "False", ",", "level", "=", "None", ")", ":", "return", "TreeViewer", "(", "self", ",", "expand", "=", "expand", ",", "level", "=", "level", ")" ]
Provide a ``print``-able display of the hierarchy. Parameters ---------- expand : bool, optional Only relevant for HTML representation. If True, tree will be fully expanded. level : int, optional Maximum depth to descend into hierarchy. Examples ...
[ "Provide", "a", "print", "-", "able", "display", "of", "the", "hierarchy", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L566-L612
train
zarr-developers/zarr
zarr/hierarchy.py
Group.create_group
def create_group(self, name, overwrite=False): """Create a sub-group. Parameters ---------- name : string Group name. overwrite : bool, optional If True, overwrite any existing array with the given name. Returns ------- g : zarr.h...
python
def create_group(self, name, overwrite=False): """Create a sub-group. Parameters ---------- name : string Group name. overwrite : bool, optional If True, overwrite any existing array with the given name. Returns ------- g : zarr.h...
[ "def", "create_group", "(", "self", ",", "name", ",", "overwrite", "=", "False", ")", ":", "return", "self", ".", "_write_op", "(", "self", ".", "_create_group_nosync", ",", "name", ",", "overwrite", "=", "overwrite", ")" ]
Create a sub-group. Parameters ---------- name : string Group name. overwrite : bool, optional If True, overwrite any existing array with the given name. Returns ------- g : zarr.hierarchy.Group Examples -------- ...
[ "Create", "a", "sub", "-", "group", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L630-L654
train
zarr-developers/zarr
zarr/hierarchy.py
Group.create_groups
def create_groups(self, *names, **kwargs): """Convenience method to create multiple groups in a single call.""" return tuple(self.create_group(name, **kwargs) for name in names)
python
def create_groups(self, *names, **kwargs): """Convenience method to create multiple groups in a single call.""" return tuple(self.create_group(name, **kwargs) for name in names)
[ "def", "create_groups", "(", "self", ",", "*", "names", ",", "**", "kwargs", ")", ":", "return", "tuple", "(", "self", ".", "create_group", "(", "name", ",", "**", "kwargs", ")", "for", "name", "in", "names", ")" ]
Convenience method to create multiple groups in a single call.
[ "Convenience", "method", "to", "create", "multiple", "groups", "in", "a", "single", "call", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L667-L669
train
zarr-developers/zarr
zarr/hierarchy.py
Group.require_group
def require_group(self, name, overwrite=False): """Obtain a sub-group, creating one if it doesn't exist. Parameters ---------- name : string Group name. overwrite : bool, optional Overwrite any existing array with given `name` if present. Returns...
python
def require_group(self, name, overwrite=False): """Obtain a sub-group, creating one if it doesn't exist. Parameters ---------- name : string Group name. overwrite : bool, optional Overwrite any existing array with given `name` if present. Returns...
[ "def", "require_group", "(", "self", ",", "name", ",", "overwrite", "=", "False", ")", ":", "return", "self", ".", "_write_op", "(", "self", ".", "_require_group_nosync", ",", "name", ",", "overwrite", "=", "overwrite", ")" ]
Obtain a sub-group, creating one if it doesn't exist. Parameters ---------- name : string Group name. overwrite : bool, optional Overwrite any existing array with given `name` if present. Returns ------- g : zarr.hierarchy.Group ...
[ "Obtain", "a", "sub", "-", "group", "creating", "one", "if", "it", "doesn", "t", "exist", "." ]
fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5
https://github.com/zarr-developers/zarr/blob/fb8e6d5ea6bc26e451e5cf0eaaee36977556d5b5/zarr/hierarchy.py#L671-L697
train