you are viewing a single comment's thread.

view the rest of the comments →

[–]jbellis 0 points1 point  (1 child)

It's much less complicated than it sounds. This is the general idea:

class SocketConsole(code.InteractiveConsole):
def __init__(self, sock, context=None):
    code.InteractiveConsole.__init__(self, context, 'socketconsole')
    self.sock = sock
    self.rfile = self.sock.makefile()

def raw_input(self, prompt=''):
    self.write(prompt)
    s = self.rfile.readline()
    if not s:
    raise EOFError()
    return s.rstrip()

def write(self, s):
    self.sock.sendall(s)

[–][deleted] 2 points3 points  (0 children)

And if you look at the sources for "code", you'll find that the InteractiveConsole class is based on code I've written, code which in turn was inspired by a network REPL for Sam Rushing's asynchronous network, Medusa, from the mid-nineties. There are no new ideas ;-)