def open_channel(self, kind, dest_addr=None, src_addr=None):
if not self.active:<EOL><INDENT>raise SSHException('<STR_LIT>')<EOL><DEDENT>self.lock.acquire()<EOL>try:<EOL><INDENT>chanid = self._next_channel()<EOL>m = Message()<EOL>m.add_byte(chr(MSG_CHANNEL_OPEN))<EOL>m.add_string(kind)<EOL>m.add_int(chanid)<EOL>m.add_int(self.window_size)<EOL>m.add_int(self.max_packet_size)<EOL>if (kind == '<STR_LIT>') or (kind == '<STR_LIT>'):<EOL><INDENT>m.add_string(dest_addr[<NUM_LIT:0>])<EOL>m.add_int(dest_addr[<NUM_LIT:1>])<EOL>m.add_string(src_addr[<NUM_LIT:0>])<EOL>m.add_int(src_addr[<NUM_LIT:1>])<EOL><DEDENT>elif kind == '<STR_LIT>':<EOL><INDENT>m.add_string(src_addr[<NUM_LIT:0>])<EOL>m.add_int(src_addr[<NUM_LIT:1>])<EOL><DEDENT>chan = Channel(chanid)<EOL>self._channels.put(chanid, chan)<EOL>self.channel_events[chanid] = event = threading.Event()<EOL>self.channels_seen[chanid] = True<EOL>chan._set_transport(self)<EOL>chan._set_window(self.window_size, self.max_packet_size)<EOL><DEDENT>finally:<EOL><INDENT>self.lock.release()<EOL><DEDENT>self._send_user_message(m)<EOL>while True:<EOL><INDENT>event.wait(<NUM_LIT:0.1>);<EOL>if not self.active:<EOL><INDENT>e = self.get_exception()<EOL>if e is None:<EOL><INDENT>e = SSHException('<STR_LIT>')<EOL><DEDENT>raise e<EOL><DEDENT>if event.isSet():<EOL><INDENT>break<EOL><DEDENT><DEDENT>chan = self._channels.get(chanid)<EOL>if chan is not None:<EOL><INDENT>return chan<EOL><DEDENT>e = self.get_exception()<EOL>if e is None:<EOL><INDENT>e = SSHException('<STR_LIT>')<EOL><DEDENT>raise e<EOL>
Request a new channel to the server.  L{Channel}s are socket-like
objects used for the actual transfer of data across the session.
You may only request a channel after negotiating encryption (using
L{connect} or L{start_client}) and authenticating.

@param kind: the kind of channel requested (usually C{"session"},
    C{"forwarded-tcpip"}, C{"direct-tcpip"}, or C{"x11"})
@type kind: str
@param dest_addr: the destination address of this port forwarding,
    if C{kind} is C{"forwarded-tcpip"} or C{"direct-tcpip"} (ignored
    for other channel types)
@type dest_addr: (str, int)
@param src_addr: the source address of this port forwarding, if
    C{kind} is C{"forwarded-tcpip"}, C{"direct-tcpip"}, or C{"x11"}
@type src_addr: (str, int)
@return: a new L{Channel} on success
@rtype: L{Channel}

@raise SSHException: if the request is rejected or the session ends
    prematurely