def __init__(self, sock):
if isinstance(sock, str):<EOL><INDENT>hl = sock.split('<STR_LIT::>', <NUM_LIT:1>)<EOL>if len(hl) == <NUM_LIT:1>:<EOL><INDENT>sock = (hl[<NUM_LIT:0>], <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>sock = (hl[<NUM_LIT:0>], int(hl[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>if type(sock) is tuple:<EOL><INDENT>hostname, port = sock<EOL>reason = '<STR_LIT>'<EOL>for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):<EOL><INDENT>if socktype == socket.SOCK_STREAM:<EOL><INDENT>af = family<EOL>addr = sockaddr<EOL>sock = socket.socket(af, socket.SOCK_STREAM)<EOL>try:<EOL><INDENT>retry_on_signal(lambda: sock.connect((hostname, port)))<EOL><DEDENT>except socket.error as e:<EOL><INDENT>reason = str(e)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise SSHException(<EOL>'<STR_LIT>' % (hostname, reason))<EOL><DEDENT><DEDENT>threading.Thread.__init__(self)<EOL>self.setDaemon(True)<EOL>self.rng = rng<EOL>self.sock = sock<EOL>try:<EOL><INDENT>self.sock.settimeout(<NUM_LIT:0.1>)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>self.packetizer = Packetizer(sock)<EOL>self.local_version = '<STR_LIT>' + self._PROTO_ID + '<STR_LIT:->' + self._CLIENT_ID<EOL>self.remote_version = '<STR_LIT>'<EOL>self.local_cipher = self.remote_cipher = '<STR_LIT>'<EOL>self.local_kex_init = self.remote_kex_init = None<EOL>self.local_mac = self.remote_mac = None<EOL>self.local_compression = self.remote_compression = None<EOL>self.session_id = None<EOL>self.host_key_type = None<EOL>self.host_key = None<EOL>self.kex_engine = None<EOL>self.H = None<EOL>self.K = None<EOL>self.active = False<EOL>self.initial_kex_done = False<EOL>self.in_kex = False<EOL>self.authenticated = False<EOL>self._expected_packet = tuple()<EOL>self.lock = threading.Lock()    <EOL>self._channels = ChannelMap()<EOL>self.channel_events = { }       <EOL>self.channels_seen = { }        <EOL>self._channel_counter = <NUM_LIT:1><EOL>self.window_size = <NUM_LIT><EOL>self.max_packet_size = <NUM_LIT><EOL>self._forward_agent_handler = None<EOL>self._x11_handler = None<EOL>self._tcp_handler = None<EOL>self.saved_exception = None<EOL>self.clear_to_send = threading.Event()<EOL>self.clear_to_send_lock = threading.Lock()<EOL>self.clear_to_send_timeout = <NUM_LIT><EOL>self.log_name = '<STR_LIT>'<EOL>self.logger = util.get_logger(self.log_name)<EOL>self.packetizer.set_log(self.logger)<EOL>self.auth_handler = None<EOL>self.global_response = None     <EOL>self.completion_event = None    <EOL>self.banner_timeout = <NUM_LIT:15>        <EOL>self.server_mode = False<EOL>self.server_object = None<EOL>self.server_key_dict = { }<EOL>self.server_accepts = [ ]<EOL>self.server_accept_cv = threading.Condition(self.lock)<EOL>self.subsystem_table = { }<EOL>
Create a new SSH session over an existing socket, or socket-like
object.  This only creates the Transport object; it doesn't begin the
SSH session yet.  Use L{connect} or L{start_client} to begin a client
session, or L{start_server} to begin a server session.

If the object is not actually a socket, it must have the following
methods:
    - C{send(str)}: Writes from 1 to C{len(str)} bytes, and
      returns an int representing the number of bytes written.  Returns
      0 or raises C{EOFError} if the stream has been closed.
    - C{recv(int)}: Reads from 1 to C{int} bytes and returns them as a
      string.  Returns 0 or raises C{EOFError} if the stream has been
      closed.
    - C{close()}: Closes the socket.
    - C{settimeout(n)}: Sets a (float) timeout on I/O operations.

For ease of use, you may also pass in an address (as a tuple) or a host
string as the C{sock} argument.  (A host string is a hostname with an
optional port (separated by C{":"}) which will be converted into a
tuple of C{(hostname, port)}.)  A socket will be connected to this
address and used for communication.  Exceptions from the C{socket} call
may be thrown in this case.

@param sock: a socket or socket-like object to create the session over.
@type sock: socket