16
globs['__builtins__'] = globals()['__builtins__']
18
compiler = codeop.CommandCompiler()
26
curr_cmd = curr_cmd + '\n' + txt
28
cmd = compiler(curr_cmd)
30
# The command was incomplete,
31
# so send back a None, so the
32
# client can print a '...'
33
web.output(cjson.encode(None))
35
# The command was complete,
37
out = cStringIO.StringIO()
41
res = eval(cmd, globs, locls)
43
v = (out.getvalue(), res, None)
44
web.output(cjson.encode(v))
46
except Exception, exc:
15
from threading import Thread
17
class StdinFromWeb(object):
18
def __init__(self, cmdQ, lineQ):
48
v = (None, None, str(exc))
49
web.output(cjson.encode(v))
25
self.cmdQ.put({"input":None})
28
# Some of our 5 seconds may have elapsed, but
33
class PythonRunner(Thread):
34
def __init__(self, cmdQ, lineQ):
41
globs['__builtins__'] = globals()['__builtins__']
43
compiler = codeop.CommandCompiler()
51
curr_cmd = curr_cmd + '\n' + l
53
cmd = compiler(curr_cmd)
55
# The command was incomplete,
56
# so send back a None, so the
57
# client can print a '...'
58
self.cmdQ.put({"more":None})
60
# The command was complete,
62
sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
63
out = cStringIO.StringIO()
67
res = eval(cmd, globs, locls)
69
self.cmdQ.put({"okay":(out.getvalue(),res)})
71
except Exception, exc:
73
self.cmdQ.put({"exc":str(exc)})
54
78
'/index.html', 'index',
98
122
# Okay, so the authentication succeeded,
99
123
# so now we have the trivial matter of actually
100
124
# executing the python....
127
sys.__stderr__.write(cjson.encode(r) + "\n")
128
web.output(cjson.encode(r))
131
lineQ = Queue.Queue()
132
interpThread = PythonRunner(cmdQ, lineQ)
103
134
if __name__ == "__main__":
105
136
magic = sys.argv[2]
106
138
web.run(urls, globals())