#NEWLINE# def _connect_socket( self ) : #NEWLINE# #INDENT# sockerr = None #NEWLINE# addresses = socket . getaddrinfo ( self . host , self . port , socket . AF_UNSPEC , socket . SOCK_STREAM ) #NEWLINE# if ( not addresses ) : #NEWLINE# #INDENT# raise ConnectionException ( ( 'getaddrinfo returned empty list for %s' % ( self . host , ) ) ) #NEWLINE# #UNINDENT# for ( af , socktype , proto , canonname , sockaddr ) in addresses : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . _socket = self . _socket_impl . socket ( af , socktype , proto ) #NEWLINE# if self . ssl_options : #NEWLINE# #INDENT# if ( not self . _ssl_impl ) : #NEWLINE# #INDENT# raise RuntimeError ( 'This version of Python was not compiled with SSL support' ) #NEWLINE# #UNINDENT# self . _socket = self . _ssl_impl . wrap_socket ( self . _socket , ** self . ssl_options ) #NEWLINE# #UNINDENT# self . _socket . settimeout ( self . connect_timeout ) #NEWLINE# self . _socket . connect ( sockaddr ) #NEWLINE# if self . _check_hostname : #NEWLINE# #INDENT# ssl . match_hostname ( self . _socket . getpeercert ( ) , self . host ) #NEWLINE# #UNINDENT# sockerr = None #NEWLINE# break #NEWLINE# #UNINDENT# except socket . error as err : #NEWLINE# #INDENT# if self . _socket : #NEWLINE# #INDENT# self . _socket . close ( ) #NEWLINE# self . _socket = None #NEWLINE# #UNINDENT# sockerr = err #NEWLINE# #UNINDENT# #UNINDENT# if sockerr : #NEWLINE# #INDENT# raise socket . error ( sockerr . errno , ( 'Tried connecting to %s. Last error: %s' % ( [ a [ 4 ] for a in addresses ] , ( sockerr . strerror or sockerr ) ) ) ) #NEWLINE# #UNINDENT# if self . sockopts : #NEWLINE# #INDENT# for args in self . sockopts : #NEWLINE# #INDENT# self . _socket . setsockopt ( * args )