25
25
self.cmdQ.put({"input":None})
28
# Some of our 5 seconds may have elapsed, but
29
# Some of our 5 seconds may have elapsed, but never mind.
33
33
class PythonRunner(Thread):
34
34
def __init__(self, cmdQ, lineQ):
41
41
compiler = codeop.CommandCompiler()
45
if self.curr_cmd == '':
48
self.curr_cmd = self.curr_cmd + '\n' + l
50
cmd = compiler(self.curr_cmd)
52
# The command was incomplete,
53
# so send back a None, so the
54
# client can print a '...'
55
self.cmdQ.put({"more":None})
47
if self.curr_cmd == '':
48
self.curr_cmd = ln['chat']
57
# The command was complete,
50
self.curr_cmd = self.curr_cmd + '\n' + ln['chat']
52
cmd = compiler(self.curr_cmd)
54
# The command was incomplete,
55
# so send back a None, so the
56
# client can print a '...'
57
self.cmdQ.put({"more":None})
59
# The command was complete,
61
sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
62
self.out = cStringIO.StringIO()
66
res = eval(cmd, globs, locls)
68
self.cmdQ.put({"okay":(self.out.getvalue(),res)})
70
except Exception, exc:
72
self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
75
# throw away a partial command.
78
cmd = compile(ln['block'], "<web session>", 'exec');
59
80
sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
60
out = cStringIO.StringIO()
81
self.out = cStringIO.StringIO()
64
85
res = eval(cmd, globs, locls)
66
self.cmdQ.put({"okay":(out.getvalue(),res)})
68
except Exception, exc:
70
self.cmdQ.put({"exc":str(exc)})
87
self.cmdQ.put({"okay":(self.out.getvalue(),res)})
89
except Exception, exc:
91
self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
73
93
def init_state(self):
126
147
# Okay, so the authentication succeeded,
127
148
# so now we have the trivial matter of actually
128
149
# executing the python....
150
lineQ.put({'chat':inp.text})
152
sys.__stderr__.write(cjson.encode(r) + "\n")
153
web.output(cjson.encode(r))
161
digest = md5.new(inp.text + magic).digest().encode('hex')
162
if inp.digest != digest:
163
web.output("401 Unauthorized")
164
web.ctx.status = '401 Unauthorized'
167
# Okay, so the authentication succeeded,
168
# so now we have the trivial matter of actually
169
# executing the python....
170
lineQ.put({'block':inp.text})
131
172
sys.__stderr__.write(cjson.encode(r) + "\n")
132
173
web.output(cjson.encode(r))