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

« back to all changes in this revision

Viewing changes to console/python-console

  • Committer: drtomc
  • Date: 2008-02-01 03:02:14 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:365
Make the console accept blocks of code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        self.out = cStringIO.StringIO()
38
38
        Thread.__init__(self)
39
39
 
 
40
    def execCmd(self, cmd):
 
41
        try:
 
42
            sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
 
43
            sys.stdout = self.out
 
44
            sys.stderr = self.out
 
45
            signal.alarm(5)
 
46
            res = eval(cmd, self.globs, self.locls)
 
47
            signal.alarm(0)
 
48
            self.cmdQ.put({"okay":(self.out.getvalue(),res)})
 
49
            self.curr_cmd = ''
 
50
            self.out = cStringIO.StringIO()
 
51
        except Exception, exc:
 
52
            signal.alarm(0)
 
53
            self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
 
54
            self.curr_cmd = ''
 
55
            self.out = cStringIO.StringIO()
 
56
 
40
57
    def run(self):
41
58
        self.init_state()
42
59
        compiler = codeop.CommandCompiler()
56
73
                        # client can print a '...'
57
74
                        self.cmdQ.put({"more":None})
58
75
                    else:
59
 
                        # The command was complete,
60
 
                        # so evaluate it!
61
 
                        sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
62
 
                        sys.stdout = self.out
63
 
                        sys.stderr = self.out
64
 
                        signal.alarm(5)
65
 
                        res = eval(cmd, self.globs, self.locls)
66
 
                        signal.alarm(0)
67
 
                        self.cmdQ.put({"okay":(self.out.getvalue(),res)})
68
 
                        self.curr_cmd = ''
69
 
                        self.out = cStringIO.StringIO()
 
76
                        self.execCmd(cmd)
70
77
                except Exception, exc:
71
78
                    signal.alarm(0)
72
79
                    self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
76
83
                # throw away a partial command.
77
84
                try:
78
85
                    cmd = compile(ln['block'], "<web session>", 'exec');
79
 
                    
80
 
                    sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
81
 
                    self.out = cStringIO.StringIO()
82
 
                    sys.stdout = self.out
83
 
                    sys.stderr = self.out
84
 
                    signal.alarm(5)
85
 
                    res = eval(cmd, self.globs, self.locls)
86
 
                    signal.alarm(0)
87
 
                    self.cmdQ.put({"okay":(self.out.getvalue(),res)})
88
 
                    self.curr_cmd = ''
89
 
                    self.out = cStringIO.StringIO()
 
86
                    self.execCmd(cmd)
90
87
                except Exception, exc:
91
88
                    signal.alarm(0)
92
89
                    self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})