def isIPAddress(addr, family=AF_INET):
 if isinstance(addr, bytes):
  try:
   addr = addr.decode('ascii')
  except UnicodeDecodeError:
   return False
 if (family == AF_INET6):
  addr = addr.split(u'%', 1)[0]
 elif (family == AF_INET):
  if (addr.count(u'.') != 3):
   return False
 else:
  raise ValueError('unknown address family {!r}'.format(family))
 try:
  inet_pton(family, addr)
 except (ValueError, error):
  return False
 return True

def isIPAddress ( addr , family = AF_INET ) : if isinstance ( addr , bytes ) : try : addr = addr . decode ( 'ascii' ) except UnicodeDecodeError : return False if ( family == AF_INET6 ) : addr = addr . split ( u'%' , 1 ) [ 0 ] elif ( family == AF_INET ) : if ( addr . count ( u'.' ) != 3 ) : return False else : raise ValueError ( 'unknown address family {!r}' . format ( family ) ) try : inet_pton ( family , addr ) except ( ValueError , error ) : return False return True
determine whether the given string represents an ipv4 address .