def __init__(self, chanid): """ Create a new channel. The channel is not associated with any particular session or `.Transport` until the Transport attaches it. Normally you would only call this method from the constructor of a subclass of `.Channel`. :param int chanid: the ID of this channel, as passed by an existing `.Transport`. """ #: Channel ID self.chanid = chanid #: Remote channel ID self.remote_chanid = 0 #: `.Transport` managing this channel self.transport = None #: Whether the connection is presently active self.active = False self.eof_received = 0 self.eof_sent = 0 self.in_buffer = BufferedPipe() self.in_stderr_buffer = BufferedPipe() self.timeout = None #: Whether the connection has been closed self.closed = False # Whether a close message has been sent; guarded with # transport.clear_to_send_lock self._close_sent = False self.ultra_debug = False self.lock = threading.Lock() self.out_buffer_cv = threading.Condition(self.lock) self.in_window_size = 0 self.out_window_size = 0 self.in_max_packet_size = 0 self.out_max_packet_size = 0 self.in_window_threshold = 0 self.in_window_sofar = 0 self.status_event = threading.Event() self._name = str(chanid) self.logger = util.get_logger('paramiko.transport') self._pipe = None self.event = threading.Event() self.event_ready = False self.combine_stderr = False self.exit_status = -1 self.origin_addr = None
def test_2_delay(self): p = BufferedPipe() self.assertTrue(not p.read_ready()) threading.Thread(target=delay_thread, args=(p, )).start() self.assertEqual(b"a", p.read(1, 0.1)) try: p.read(1, 0.1) self.assertTrue(False) except PipeTimeout: pass self.assertEqual(b"b", p.read(1, 1.0)) self.assertEqual(b"", p.read(1))
def __init__(self, chanid): """ Create a new channel. The channel is not associated with any particular session or L{Transport} until the Transport attaches it. Normally you would only call this method from the constructor of a subclass of L{Channel}. @param chanid: the ID of this channel, as passed by an existing L{Transport}. @type chanid: int """ self.chanid = chanid self.remote_chanid = 0 self.transport = None self.active = False self.eof_received = 0 self.eof_sent = 0 self.in_buffer = BufferedPipe() self.in_stderr_buffer = BufferedPipe() self.timeout = None self.closed = False self.ultra_debug = False self.lock = threading.Lock() self.out_buffer_cv = threading.Condition(self.lock) self.in_window_size = 0 self.out_window_size = 0 self.in_max_packet_size = 0 self.out_max_packet_size = 0 self.in_window_threshold = 0 self.in_window_sofar = 0 self.status_event = threading.Event() self._name = str(chanid) self.logger = util.get_logger('paramiko.transport') self._pipe = None self.event = threading.Event() self.event_ready = False self.combine_stderr = False self.exit_status = -1 self.origin_addr = None
def test_1_buffered_pipe(self): p = BufferedPipe() self.assertTrue(not p.read_ready()) p.feed("hello.") self.assertTrue(p.read_ready()) data = p.read(6) self.assertEqual(b"hello.", data) p.feed("plus/minus") self.assertEqual(b"plu", p.read(3)) self.assertEqual(b"s/m", p.read(3)) self.assertEqual(b"inus", p.read(4)) p.close() self.assertTrue(not p.read_ready()) self.assertEqual(b"", p.read(1))
def test_1_buffered_pipe(self): p = BufferedPipe() self.assert_(not p.read_ready()) p.feed('hello.') self.assert_(p.read_ready()) data = p.read(6) self.assertEquals('hello.', data) p.feed('plus/minus') self.assertEquals('plu', p.read(3)) self.assertEquals('s/m', p.read(3)) self.assertEquals('inus', p.read(4)) p.close() self.assert_(not p.read_ready()) self.assertEquals('', p.read(1))
def test_3_close_while_reading(self): p = BufferedPipe() threading.Thread(target=close_thread, args=(p, )).start() data = p.read(1, 1.0) self.assertEqual(b"", data)