Esempio n. 1
0
def verify_auth_dest_number(destination_number):
    """
    >>> verify_auth_dest_number('1234567890')
    {
        'authorized': 0,
        'country_id': 0,
        'prefix_id': 0,
    }
    """
    # remove prefix
    sanitized_destination = remove_prefix(destination_number,
                                          settings.PREFIX_TO_IGNORE)

    prefix_list = prefix_list_string(sanitized_destination)

    authorized = 1  # default
    # check destion against whitelist
    authorized = chk_prefix_in_whitelist(prefix_list)
    if authorized:
        authorized = 1
    else:
        # check against blacklist
        authorized = chk_prefix_in_blacklist(prefix_list)
        if not authorized:
            # not allowed destination
            authorized = 0

    if (len(sanitized_destination) < settings.PN_MIN_DIGITS
            or sanitized_destination[:1].isalpha()):
        # It might be an extension
        country_id = None
        prefix_id = None
    elif (prefix_list and len(sanitized_destination) >= settings.PN_MIN_DIGITS
          and len(sanitized_destination) <= settings.PN_MAX_DIGITS):
        # It might be an local call
        # Need to add coma for get_country_id_prefix to eval correctly
        prefix_list = prefix_list_string(
            str(settings.LOCAL_DIALCODE) + sanitized_destination)
        (country_id, prefix_id) = get_country_id_prefix(prefix_list)
    else:
        # International call
        (country_id, prefix_id) = get_country_id_prefix(prefix_list)

    destination_data = {
        'authorized': authorized,
        'country_id': country_id,
        'prefix_id': prefix_id,
    }
    return destination_data
def verify_auth_dest_number(destination_number):
    """
    >>> verify_auth_dest_number('1234567890')
    {
        'authorized': 0,
        'country_id': 0,
        'prefix_id': 0,
    }
    """
    # remove prefix
    sanitized_destination = remove_prefix(destination_number, settings.PREFIX_TO_IGNORE)

    prefix_list = prefix_list_string(sanitized_destination)

    authorized = 1  # default
    # check destion against whitelist
    authorized = chk_prefix_in_whitelist(prefix_list)
    if authorized:
        authorized = 1
    else:
        # check against blacklist
        authorized = chk_prefix_in_blacklist(prefix_list)
        if not authorized:
            # not allowed destination
            authorized = 0

    if (len(sanitized_destination) < settings.PN_MIN_DIGITS
            or sanitized_destination[:1].isalpha()):
        # It might be an extension
        country_id = None
        prefix_id = None
    elif (prefix_list
          and len(sanitized_destination) >= settings.PN_MIN_DIGITS
          and len(sanitized_destination) <= settings.PN_MAX_DIGITS):
        # It might be an local call
        # Need to add coma for get_country_id_prefix to eval correctly
        prefix_list = prefix_list_string(str(settings.LOCAL_DIALCODE) + sanitized_destination)
        (country_id, prefix_id) = get_country_id_prefix(prefix_list)
    else:
        # International call
        (country_id, prefix_id) = get_country_id_prefix(prefix_list)

    destination_data = {
        'authorized': authorized,
        'country_id': country_id,
        'prefix_id': prefix_id,
    }
    return destination_data
Esempio n. 3
0
def chk_destination(destination_number):
    #remove prefix
    sanitized_destination = remove_prefix(destination_number,
        settings.PREFIX_TO_IGNORE)

    prefix_list = prefix_list_string(sanitized_destination)

    authorized = 1  # default
    # check destion against whitelist
    authorized = chk_prefix_in_whitelist(prefix_list)
    if authorized:
        authorized = 1
    else:
        # check against blacklist
        authorized = chk_prefix_in_blacklist(prefix_list)
        if not authorized:
            # not allowed destination
            authorized = 0

    if len(sanitized_destination) < settings.PN_MIN_DIGITS:
        # It might be an extension
        country_id = 0
    elif len(sanitized_destination) >= settings.PN_MIN_DIGITS\
    and len(sanitized_destination) <= settings.PN_MAX_DIGITS:
        # It might be an local call
        # Need to add coma for get_country_id to eval correctly
        country_id = get_country_id(str(settings.LOCAL_DIALCODE) + ',')
    else:
        # International call
        country_id = get_country_id(prefix_list)

    destination_data = {
        'authorized': authorized,
        'country_id': country_id,
        }
    return destination_data