Beispiel #1
0
def test_select_returns_streams_for_reading():
    a, b = socket.socketpair()
    a.send(b'test')
    expect(io.select([a, b], timeout=0)).to(equal([b]))
    b.send(b'test')
    expect(io.select([a, b], timeout=0)).to(equal([a, b]))
    b.recv(4)
    expect(io.select([a, b], timeout=0)).to(equal([a]))
    a.recv(4)
    expect(io.select([a, b], timeout=0)).to(equal([]))
Beispiel #2
0
def test_select_returns_streams_for_reading():
        a, b = socket.socketpair()
        a.send('test')
        expect(io.select([a, b], timeout=0)).to.equal([b])
        b.send('test')
        expect(io.select([a, b], timeout=0)).to.equal([a, b])
        b.recv(4)
        expect(io.select([a, b], timeout=0)).to.equal([a])
        a.recv(4)
        expect(io.select([a, b], timeout=0)).to.equal([])
Beispiel #3
0
 def _hijack_tty(self, pumps):
     with tty.Terminal(sys.stdin, raw=self.israw()):
         self.resize()
         while True:
             _ready = io.select(pumps, timeout=60)
             if all([p.flush() is None for p in pumps]):
                 break
Beispiel #4
0
    def _hijack_tty(self, pumps):
        with tty.Terminal(self.stdin, raw=self.israw()):
            self.resize()
            while True:
                read_pumps = [p for p in pumps if not p.eof]
                write_streams = [
                    p.to_stream for p in pumps if p.to_stream.needs_write()
                ]

                read_ready, write_ready = io.select(read_pumps,
                                                    write_streams,
                                                    timeout=60)
                try:
                    for write_stream in write_ready:
                        write_stream.do_write()

                    for pump in read_ready:
                        pump.flush()

                    if all([p.is_done() for p in pumps]):
                        break

                except SSLError as e:
                    if 'The operation did not complete' not in e.strerror:
                        raise e
Beispiel #5
0
 def _hijack_tty(self, pumps):
     with tty.Terminal(sys.stdin, raw=self.israw()):
         self.resize()
         while True:
             ready = io.select(pumps, timeout=1)
             if not all([p.flush() is not None for p in ready]):
                 break
Beispiel #6
0
 def _hijack_tty(self, pumps):
     with tty.Terminal(sys.stdin, raw=self.israw()):
         self.resize()
         while True:
             ready = io.select(pumps, timeout=60)
             try:
                 if any([p.flush() is None for p in ready]):
                     break
             except SSLError as e:
                 if 'The operation did not complete' not in e.strerror:
                     raise e
Beispiel #7
0
 def _hijack_tty(self, pumps):
     with tty.Terminal(sys.stdin, raw=self.israw()):
         self.resize()
         while True:
             _ready = io.select(pumps, timeout=60)
             try:
                 if all([p.flush() is None for p in pumps]):
                     break
             except SSLError as e:
                 if 'The operation did not complete' not in e.strerror:
                     raise e
Beispiel #8
0
    def _hijack_tty(self, pumps):
        with tty.Terminal(self.stdin, raw=self.israw()):
            self.resize()
            while True:
                read_pumps = [p for p in pumps if not p.eof]
                write_streams = [p.to_stream for p in pumps if p.to_stream.needs_write()]

                read_ready, write_ready = io.select(read_pumps, write_streams, timeout=60)
                try:
                    for write_stream in write_ready:
                        write_stream.do_write()

                    for pump in read_ready:
                        pump.flush()

                    if all([p.is_done() for p in pumps]):
                        break

                except SSLError as e:
                    if 'The operation did not complete' not in e.strerror:
                        raise e
Beispiel #9
0
    def _hijack_tty(self, pumps):
        with tty.Terminal(self.operation.stdin, raw=self.operation.israw()):
            self.resize()
            keep_running = True
            stdin_stream = self._get_stdin_pump(pumps)
            while keep_running:
                read_pumps = [p for p in pumps if not p.eof]
                write_streams = [
                    p.to_stream for p in pumps if p.to_stream.needs_write()
                ]

                read_ready, write_ready = io.select(read_pumps,
                                                    write_streams,
                                                    timeout=2)
                try:
                    for write_stream in write_ready:
                        write_stream.do_write()

                    for pump in read_ready:
                        pump.flush()

                    if sys.stdin.isatty():
                        if all([p.is_done() for p in pumps]):
                            keep_running = False
                    elif stdin_stream.is_done():
                        # If stdin isn't a TTY, this is probably an SSH session.
                        # The most common use case for an SSH session without a
                        # TTY is SCP/SFTP; like, someone coping a file to a remote
                        # server. Those file transfer clients mark the end of
                        # the session by sending an empty packet, then waiting
                        # for the TCP session to terminate, We need to break out
                        # of this loop to return control to the calling application
                        # so it can tear down the SCP/SFTP process running inside
                        # the container.
                        keep_running = False
                        break

                except SSLError as e:
                    if 'The operation did not complete' not in e.strerror:
                        raise e
Beispiel #10
0
def test_select_returns_streams_for_writing():
    a, b = socket.socketpair()
    expect(io.select([a, b], [a, b], timeout=0)).to(equal(([], [a, b])))