def posix_shell(chan, encoding='UTF-8'):
    try:
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = chan.recv(1024)
                    if len(x) == 0:
                        sys.stdout.write('\r\n*** EOF ***\r\n')
                        break
                    print(x.decode(encoding), end='')
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read()
                chan.send(x.encode(encoding))
    except Exception as e:
        print('Exception in TTY session\n%r\n' % e)
dataset/ETHPy150Open radssh/radssh/radssh/core_plugins/test_tty.py/posix_shell/original