4
# python-console <port> <magic>
12
globs['__builtins__'] = globals()['__builtins__']
14
compiler = codeop.CommandCompiler()
21
curr_cmd = curr_cmd + '\n' + txt
23
cmd = compiler(curr_cmd)
25
# The command was incomplete,
26
# so send back a None, so the
27
# client can print a '...'
28
web.output(cjson.encode(None))
30
# The command was complete,
32
out = cStringIO.StringIO()
36
res = eval(cmd, globs, locls)
38
v = (out.getvalue(), res, None)
39
web.output(json.encode(v))
41
except Exception, exc:
42
v = (None, None, str(exc))
43
web.output(json.encode(v))
48
'/(.*\.js)', 'jscript',
51
# The global 'magic' is the secret that the client and server share
52
# which is used to create and md5 digest to authenticate requests.
53
# It is assigned a real value at startup.
61
digest = md5.new('hello' + magic).digest().encode('hex')
62
if inp.digest != digest:
63
web.ctx.status = '401 Unauthorized'
66
# Okay, so the authentication succeeded,
67
# so all we need to do is send back the static
68
# HTML for the console app.
69
web.output(file("index.html", "r").read())
73
web.output(file(name, "r").read())
80
digest = md5.new(inp.text + magic).digest().encode('hex')
81
if inp.digest != digest:
82
web.ctx.status = '401 Unauthorized'
85
# Okay, so the authentication succeeded,
86
# so now we have the trivial matter of actually
87
# executing the python....
88
web.output(do_chat(inp.text))
90
if __name__ == "__main__":
93
web.run(urls, globals())