

def format_out_of_country_calling_number(numobj, region_calling_from):
    'Formats a phone number for out-of-country dialing purposes.\n\n    If no region_calling_from is supplied, we format the number in its\n    INTERNATIONAL format. If the country calling code is the same as that of\n    the region where the number is from, then NATIONAL formatting will be\n    applied.\n\n    If the number itself has a country calling code of zero or an otherwise\n    invalid country calling code, then we return the number with no formatting\n    applied.\n\n    Note this function takes care of the case for calling inside of NANPA and\n    between Russia and Kazakhstan (who share the same country calling\n    code). In those cases, no international prefix is used. For regions which\n    have multiple international prefixes, the number in its INTERNATIONAL\n    format will be returned instead.\n\n    Arguments:\n    numobj -- The phone number to be formatted\n    region_calling_from -- The region where the call is being placed\n\n    Returns the formatted phone number\n    '
    if (not _is_valid_region_code(region_calling_from)):
        return format_number(numobj, PhoneNumberFormat.INTERNATIONAL)
    country_code = numobj.country_code
    nsn = national_significant_number(numobj)
    if (not _has_valid_country_calling_code(country_code)):
        return nsn
    if (country_code == _NANPA_COUNTRY_CODE):
        if is_nanpa_country(region_calling_from):
            return ((unicod(country_code) + U_SPACE) + format_number(numobj, PhoneNumberFormat.NATIONAL))
    elif (country_code == country_code_for_valid_region(region_calling_from)):
        return format_number(numobj, PhoneNumberFormat.NATIONAL)
    metadata_for_region_calling_from = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_calling_from.upper())
    international_prefix = metadata_for_region_calling_from.international_prefix
    i18n_prefix_for_formatting = U_EMPTY_STRING
    i18n_match = fullmatch(_UNIQUE_INTERNATIONAL_PREFIX, international_prefix)
    if i18n_match:
        i18n_prefix_for_formatting = international_prefix
    elif (metadata_for_region_calling_from.preferred_international_prefix is not None):
        i18n_prefix_for_formatting = metadata_for_region_calling_from.preferred_international_prefix
    region_code = region_code_for_country_code(country_code)
    metadata_for_region = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_code.upper())
    formatted_national_number = _format_nsn(nsn, metadata_for_region, PhoneNumberFormat.INTERNATIONAL)
    formatted_number = _maybe_append_formatted_extension(numobj, metadata_for_region, PhoneNumberFormat.INTERNATIONAL, formatted_national_number)
    if (len(i18n_prefix_for_formatting) > 0):
        formatted_number = ((((i18n_prefix_for_formatting + U_SPACE) + unicod(country_code)) + U_SPACE) + formatted_number)
    else:
        formatted_number = _prefix_number_with_country_calling_code(country_code, PhoneNumberFormat.INTERNATIONAL, formatted_number)
    return formatted_number

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