def validate_and_normalize_address(address):
 new_address = address.lstrip('[').rstrip(']')
 if (address.startswith('[') and address.endswith(']')):
  return validate_and_normalize_ip(new_address)
 new_address = new_address.lower()
 if is_valid_ipv4(new_address):
  return new_address
 elif is_valid_ipv6(new_address):
  return expand_ipv6(new_address)
 elif is_valid_hostname(new_address):
  return new_address
 else:
  raise ValueError(('Invalid address %s' % address))

def validate_and_normalize_address ( address ) : new_address = address . lstrip ( '[' ) . rstrip ( ']' ) if ( address . startswith ( '[' ) and address . endswith ( ']' ) ) : return validate_and_normalize_ip ( new_address ) new_address = new_address . lower ( ) if is_valid_ipv4 ( new_address ) : return new_address elif is_valid_ipv6 ( new_address ) : return expand_ipv6 ( new_address ) elif is_valid_hostname ( new_address ) : return new_address else : raise ValueError ( ( 'Invalid address %s' % address ) )
return normalized address if the address is a valid ip or hostname .