#NEWLINE# def _connect_tcp( self , peer_addr , conn_handler , time_out = None , bind_address = None , password = None ) : #NEWLINE# #INDENT# 'Creates a TCP connection to given peer address.\n\n        Tries to create a socket for `timeout` number of seconds. If\n        successful, uses the socket instance to start `client_factory`.\n        The socket is bound to `bind_address` if specified.\n        ' #NEWLINE# LOG . debug ( 'Connect TCP called for %s:%s' , peer_addr [ 0 ] , peer_addr [ 1 ] ) #NEWLINE# if netaddr . valid_ipv4 ( peer_addr [ 0 ] ) : #NEWLINE# #INDENT# family = socket . AF_INET #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# family = socket . AF_INET6 #NEWLINE# #UNINDENT# with Timeout ( time_out , socket . error ) : #NEWLINE# #INDENT# sock = socket . socket ( family ) #NEWLINE# if bind_address : #NEWLINE# #INDENT# sock . bind ( bind_address ) #NEWLINE# #UNINDENT# if password : #NEWLINE# #INDENT# sockopt . set_tcp_md5sig ( sock , peer_addr [ 0 ] , password ) #NEWLINE# #UNINDENT# sock . connect ( peer_addr ) #NEWLINE# #UNINDENT# local = self . get_localname ( sock ) [ 0 ] #NEWLINE# remote = self . get_remotename ( sock ) [ 0 ] #NEWLINE# conn_name = ( ( ( 'L: ' + local ) + ', R: ' ) + remote ) #NEWLINE# self . _asso_socket_map [ conn_name ] = sock #NEWLINE# self . _spawn ( conn_name , conn_handler , sock ) #NEWLINE# return sock