def _create_connection(address, options):
 (host, port) = address
 if host.endswith('.sock'):
  if (not hasattr(socket, 'AF_UNIX')):
   raise ConnectionFailure('UNIX-sockets are not supported on this system')
  sock = socket.socket(socket.AF_UNIX)
  _set_non_inheritable_non_atomic(sock.fileno())
  try:
   sock.connect(host)
   return sock
  except socket.error:
   sock.close()
   raise
 family = socket.AF_INET
 if (socket.has_ipv6 and (host != 'localhost')):
  family = socket.AF_UNSPEC
 err = None
 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  (af, socktype, proto, dummy, sa) = res
  try:
   sock = socket.socket(af, (socktype | getattr(socket, 'SOCK_CLOEXEC', 0)), proto)
  except socket.error:
   sock = socket.socket(af, socktype, proto)
  _set_non_inheritable_non_atomic(sock.fileno())
  try:
   sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
   sock.settimeout(options.connect_timeout)
   sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, options.socket_keepalive)
   sock.connect(sa)
   return sock
  except socket.error as e:
   err = e
   sock.close()
 if (err is not None):
  raise err
 else:
  raise socket.error('getaddrinfo failed')

def _create_connection ( address , options ) : ( host , port ) = address if host . endswith ( '.sock' ) : if ( not hasattr ( socket , 'AF_UNIX' ) ) : raise ConnectionFailure ( 'UNIX-sockets are not supported on this system' ) sock = socket . socket ( socket . AF_UNIX ) _set_non_inheritable_non_atomic ( sock . fileno ( ) ) try : sock . connect ( host ) return sock except socket . error : sock . close ( ) raise family = socket . AF_INET if ( socket . has_ipv6 and ( host != 'localhost' ) ) : family = socket . AF_UNSPEC err = None for res in socket . getaddrinfo ( host , port , family , socket . SOCK_STREAM ) : ( af , socktype , proto , dummy , sa ) = res try : sock = socket . socket ( af , ( socktype | getattr ( socket , 'SOCK_CLOEXEC' , 0 ) ) , proto ) except socket . error : sock = socket . socket ( af , socktype , proto ) _set_non_inheritable_non_atomic ( sock . fileno ( ) ) try : sock . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 ) sock . settimeout ( options . connect_timeout ) sock . setsockopt ( socket . SOL_SOCKET , socket . SO_KEEPALIVE , options . socket_keepalive ) sock . connect ( sa ) return sock except socket . error as e : err = e sock . close ( ) if ( err is not None ) : raise err else : raise socket . error ( 'getaddrinfo failed' )
connect to *address* and return the socket object .