diff options
author | Edgar Sousa <edg@edgsousa.xyz> | 2018-06-12 10:37:37 +0100 |
---|---|---|
committer | edgsousa <mythund3r> | 2018-06-12 10:37:37 +0100 |
commit | 7696885e88e97b99a96069890a7143de7f3a40aa (patch) | |
tree | e6fd1757c66f9ba88596f78a578bd548c646560d /demos/interactive.py | |
parent | 369c85d32f3ebe392c9f085347d48c0791b563fc (diff) | |
parent | 6efe46d6ab0ad2daba436dc0aaed29f57b13bd2c (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'demos/interactive.py')
-rw-r--r-- | demos/interactive.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/demos/interactive.py b/demos/interactive.py index 7138cd6c..037787c4 100644 --- a/demos/interactive.py +++ b/demos/interactive.py @@ -25,6 +25,7 @@ from paramiko.py3compat import u try: import termios import tty + has_termios = True except ImportError: has_termios = False @@ -39,7 +40,7 @@ def interactive_shell(chan): def posix_shell(chan): import select - + oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) @@ -52,7 +53,7 @@ def posix_shell(chan): try: x = u(chan.recv(1024)) if len(x) == 0: - sys.stdout.write('\r\n*** EOF\r\n') + sys.stdout.write("\r\n*** EOF\r\n") break sys.stdout.write(x) sys.stdout.flush() @@ -67,26 +68,28 @@ def posix_shell(chan): finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) - + # thanks to Mike Looijmans for this code def windows_shell(chan): import threading - sys.stdout.write("Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n") - + sys.stdout.write( + "Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n" + ) + def writeall(sock): while True: data = sock.recv(256) if not data: - sys.stdout.write('\r\n*** EOF ***\r\n\r\n') + sys.stdout.write("\r\n*** EOF ***\r\n\r\n") sys.stdout.flush() break sys.stdout.write(data) sys.stdout.flush() - + writer = threading.Thread(target=writeall, args=(chan,)) writer.start() - + try: while True: d = sys.stdin.read(1) |