python - code.interact() doesn't understand arrow keys when stdin is set to a socket -


i'm making lightweight manhole-like remote interactive python shell setting stdin, stdout, stderr socket , calling code.interact().

this works beautifully except arrow keys showing ^[[c when connect via nc localhost 1337.

it's not issue of not having readline installed, works fine when launch interpreter manually, if run code.interact(). issue occurs through sockets. can import readline inside remote shell nothing.

perhaps i'm missing related readline in socketwrapper.read()?

import socket import sys import readline readline.parse_and_bind('tab: complete') # doesn't work import code  port = 1337  while true:     sock = socket.socket()     sock.setsockopt(socket.sol_socket, socket.so_reuseaddr, 1)     sock.bind(('', port))     sock.listen(1)     print("~listening on port %d~" % port)     connection, connection_addr = sock.accept()     print("accepted connection %s." % (connection_addr,))      class socketwrapper:         def __init__(self, sock):             self.sock = sock          def read(self, length):             return self.sock.recv(length)          def write(self, text):             return self.sock.send(text)          def readline(self):             return self.sock.makefile().readline()      sockfile = socketwrapper(connection)      sys.stdin = sockfile     sys.stdout = sockfile     sys.stderr = sockfile      code.interact(         local=dict(globals(), **locals())     ) 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -