Logo Search packages:      
Sourcecode: paramiko version File versions  Download package

def paramiko::transport::Transport::__init__ (   self,
  sock 
)

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

Definition at line 196 of file transport.py.

00196                             :
        """
        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
        """
        if type(sock) is str:
            # convert "host:port" into (host, port)
            hl = sock.split(':', 1)
            if len(hl) == 1:
                sock = (hl[0], 22)
            else:
                sock = (hl[0], int(hl[1]))
        if type(sock) is tuple:
            # connect to the given (host, port)
            hostname, port = sock
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((hostname, port))
        # okay, normal socket-ish flow here...
        threading.Thread.__init__(self)
        self.randpool = randpool
        self.sock = sock
        # Python < 2.3 doesn't have the settimeout method - RogerB
        try:
            # we set the timeout so we can check self.active periodically to
            # see if we should bail.  socket.timeout exception is never
            # propagated.
            self.sock.settimeout(0.1)
        except AttributeError:
            pass
        # negotiated crypto parameters
        self.packetizer = Packetizer(sock)
        self.local_version = 'SSH-' + self._PROTO_ID + '-' + self._CLIENT_ID
        self.remote_version = ''
        self.local_cipher = self.remote_cipher = ''
        self.local_kex_init = self.remote_kex_init = None
        self.session_id = None
        # /negotiated crypto parameters
        self.expected_packet = 0
        self.active = False
        self.initial_kex_done = False
        self.in_kex = False
        self.lock = threading.Lock()    # synchronization (always higher level than write_lock)
        self.channels = weakref.WeakValueDictionary()   # (id -> Channel)
        self.channel_events = { }       # (id -> Event)
        self.channels_seen = { }        # (id -> True)
        self.channel_counter = 1
        self.window_size = 65536
        self.max_packet_size = 34816
        self.saved_exception = None
        self.clear_to_send = threading.Event()
        self.clear_to_send_lock = threading.Lock()
        self.log_name = 'paramiko.transport'
        self.logger = util.get_logger(self.log_name)
        self.packetizer.set_log(self.logger)
        self.auth_handler = None
        self.authenticated = False
        # user-defined event callbacks:
        self.completion_event = None
        # server mode:
        self.server_mode = False
        self.server_object = None
        self.server_key_dict = { }
        self.server_accepts = [ ]
        self.server_accept_cv = threading.Condition(self.lock)
        self.subsystem_table = { }

    def __del__(self):


Generated by  Doxygen 1.6.0   Back to index