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