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',
49
'/(.*\.css)', 'style',
52
# The global 'magic' is the secret that the client and server share
53
# which is used to create and md5 digest to authenticate requests.
54
# It is assigned a real value at startup.
62
digest = md5.new('hello' + magic).digest().encode('hex')
63
if inp.digest != digest:
64
web.ctx.status = '401 Unauthorized'
67
# Okay, so the authentication succeeded,
68
# so all we need to do is send back the static
69
# HTML for the console app.
70
web.output(file("index.html", "r").read())
74
web.output(file(name, "r").read())
78
web.output(file(name, "r").read())
85
digest = md5.new(inp.text + magic).digest().encode('hex')
86
if inp.digest != digest:
87
web.ctx.status = '401 Unauthorized'
90
# Okay, so the authentication succeeded,
91
# so now we have the trivial matter of actually
92
# executing the python....
93
web.output(do_chat(inp.text))
95
if __name__ == "__main__":
98
web.run(urls, globals())