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

« back to all changes in this revision

Viewing changes to console/python-console

  • Committer: mattgiuca
  • Date: 2007-12-21 03:21:27 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:120
setup.py: Added command-line argument mode for conf. This completely works!

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