

def _extract_country_code(number):
    "Extracts country calling code from number.\n\n    Returns a 2-tuple of (country_calling_code, rest_of_number).  It assumes\n    that the leading plus sign or IDD has already been removed.  Returns (0,\n    number) if number doesn't start with a valid country calling code.\n    "
    if ((len(number) == 0) or (number[0] == U_ZERO)):
        return (0, number)
    for ii in range(1, (min(len(number), _MAX_LENGTH_COUNTRY_CODE) + 1)):
        try:
            country_code = int(number[:ii])
            if (country_code in COUNTRY_CODE_TO_REGION_CODE):
                return (country_code, number[ii:])
        except Exception:
            pass
    return (0, number)

dataset/ETHPy150Open daviddrysdale/python-phonenumbers/python/phonenumbers/phonenumberutil.py _extract_country_code/original