def is_loopback_ip_address(ip=None, addrinfo=None):
 if addrinfo:
  if ((addrinfo[0] == socket.AF_INET) or (addrinfo[0] == socket.AF_INET6)):
   ip = addrinfo[4]
 if (not isinstance(ip, basestring)):
  return False
 if (ip.count('.') == 3):
  return ip.lower().startswith(('127', '::127', '0:0:0:0:0:0:127', '::ffff:127', '0:0:0:0:0:ffff:127'))
 return ((ip == '::1') or (ip == '0:0:0:0:0:0:0:1'))

def is_loopback_ip_address ( ip = None , addrinfo = None ) : if addrinfo : if ( ( addrinfo [ 0 ] == socket . AF_INET ) or ( addrinfo [ 0 ] == socket . AF_INET6 ) ) : ip = addrinfo [ 4 ] if ( not isinstance ( ip , basestring ) ) : return False if ( ip . count ( '.' ) == 3 ) : return ip . lower ( ) . startswith ( ( '127' , '::127' , '0:0:0:0:0:0:127' , '::ffff:127' , '0:0:0:0:0:ffff:127' ) ) return ( ( ip == '::1' ) or ( ip == '0:0:0:0:0:0:0:1' ) )
determines whether the address appears to be a loopback address .