~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to console/python-console

  • Committer: drtomc
  • Date: 2008-01-02 04:45:20 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:126
A basic version of the console going!

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# usage:
4
4
#   python-console <port> <magic>
5
5
 
 
6
import sys
6
7
import web
7
8
import md5
8
9
import codeop
9
10
import cjson
 
11
import cgi
 
12
import cStringIO
 
13
import signal
10
14
 
11
15
globs = {}
12
16
globs['__builtins__'] = globals()['__builtins__']
15
19
curr_cmd = ''
16
20
 
17
21
def do_chat(txt):
 
22
    global curr_cmd
18
23
    if curr_cmd == '':
19
24
        curr_cmd = txt
20
25
    else:
36
41
            res = eval(cmd, globs, locls)
37
42
            signal.alarm(0)
38
43
            v = (out.getvalue(), res, None)
39
 
            web.output(json.encode(v))
 
44
            web.output(cjson.encode(v))
40
45
            curr_cmd = ''
41
46
    except Exception, exc:
42
47
        v = (None, None, str(exc))
43
 
        web.output(json.encode(v))
 
48
        web.output(cjson.encode(v))
44
49
        curr_cmd = ''
45
50
 
46
51
urls = (
47
52
    '/',            'index',
 
53
    '/index.html',  'index',
48
54
    '/(.*\.js)',    'jscript',
49
55
    '/(.*\.css)',   'style',
50
56
    '/chat',        'chat')
80
86
class chat:
81
87
    def POST(self):
82
88
        inp = web.input()
 
89
        sys.stderr.write(str(inp) + "\n")
83
90
 
84
91
        # Authenticate
85
92
        digest = md5.new(inp.text + magic).digest().encode('hex')
90
97
        # Okay, so the authentication succeeded,
91
98
        # so now we have the trivial matter of actually
92
99
        # executing the python....
93
 
        web.output(do_chat(inp.text))
 
100
        do_chat(inp.text)
94
101
 
95
102
if __name__ == "__main__":
96
103
    # FIXME jail!