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
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
def test_raw_with_block(self): fd, __ = pty.openpty() fd = os.fdopen(fd) with tty.Terminal(fd, raw=True): expect(israw(fd)).to(be_true) expect(israw(fd)).to(be_false)
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
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
def test_repr(self): fd = 'some_fd' terminal = tty.Terminal(fd, raw=True) expect(repr(terminal)).to(equal("Terminal(some_fd, raw=True)"))
def test_start_does_not_crash_when_fd_is_not_a_tty(self): with tempfile.TemporaryFile() as f: terminal = tty.Terminal(f, raw=True) terminal.start() terminal.stop()
def test_stop_when_raw(self): fd, __ = pty.openpty() terminal = tty.Terminal(os.fdopen(fd), raw=True) terminal.start() terminal.stop() expect(israw(fd)).to(be_false)
def test_start_when_not_raw(self): fd, __ = pty.openpty() terminal = tty.Terminal(os.fdopen(fd), raw=False) expect(israw(fd)).to.be.false terminal.start() expect(israw(fd)).to.be.false