def validate_and_normalize_ip(ip):
    # first convert to lower case
    new_ip = ip.lower()
    if is_valid_ipv4(new_ip):
        return new_ip
    elif is_valid_ipv6(new_ip):
        return expand_ipv6(new_ip)
    else:
        raise ValueError('Invalid ip %s' % ip)
Return normalized ip if the ip is a valid ip.
dataset/ETHPy150Open openstack/swift/swift/common/ring/utils.py/validate_and_normalize_ip