def ip_address(address):
 try:
  return IPv4Address(address)
 except (AddressValueError, NetmaskValueError):
  pass
 try:
  return IPv6Address(address)
 except (AddressValueError, NetmaskValueError):
  pass
 raise ValueError(('%r does not appear to be an IPv4 or IPv6 address' % address))

def ip_address ( address ) : try : return IPv4Address ( address ) except ( AddressValueError , NetmaskValueError ) : pass try : return IPv6Address ( address ) except ( AddressValueError , NetmaskValueError ) : pass raise ValueError ( ( '%r does not appear to be an IPv4 or IPv6 address' % address ) )
take an ip string/int and return an object of the correct type .