4
# python-console <port> <magic>
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:
48
v = (None, None, str(exc))
49
web.output(cjson.encode(v))
54
'/index.html', 'index',
55
'/(.*\.js)', 'jscript',
56
'/(.*\.css)', 'style',
59
# The global 'magic' is the secret that the client and server share
60
# which is used to create and md5 digest to authenticate requests.
61
# It is assigned a real value at startup.
69
digest = md5.new('hello' + magic).digest().encode('hex')
70
if inp.digest != digest:
71
web.ctx.status = '401 Unauthorized'
74
# Okay, so the authentication succeeded,
75
# so all we need to do is send back the static
76
# HTML for the console app.
77
web.output(file("index.html", "r").read())
81
web.output(file(name, "r").read())
85
web.output(file(name, "r").read())
90
sys.stderr.write(str(inp) + "\n")
93
digest = md5.new(inp.text + magic).digest().encode('hex')
94
if inp.digest != digest:
95
web.ctx.status = '401 Unauthorized'
98
# Okay, so the authentication succeeded,
99
# so now we have the trivial matter of actually
100
# executing the python....
103
if __name__ == "__main__":
106
web.run(urls, globals())