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

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: mattgiuca
  • Date: 2008-02-29 02:16:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:626
tutorial: More of the same (replace os.sep with '/').

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import common.chat
18
18
 
19
19
class Interrupt(Exception):
20
 
    def __init__(self):
21
 
        Exception.__init__(self, "Interrupted!")
 
20
    pass
22
21
 
23
22
class ExpiryTimer(object):
24
23
    def __init__(self, idle):
48
47
        ln = self.lineQ.get()
49
48
        if 'chat' in ln:
50
49
            return ln['chat']
51
 
        if 'interrupt' in ln:
52
 
            raise Interrupt()
53
50
 
54
51
class StdoutToWeb(object):
55
52
    def __init__(self, cmdQ, lineQ):
58
55
        self.remainder = ''
59
56
 
60
57
    def write(self, stuff):
61
 
        # if there's less than 1K, buffer
62
 
        if len(self.remainder) + len(stuff) < 128:
63
 
            self.remainder = self.remainder + stuff
64
 
            return
65
 
 
66
58
        # Split the content up into lines, and ship all the completed
67
59
        # lines off to the server.
68
60
        lines = stuff.split("\n")
92
84
    def __init__(self, cmdQ, lineQ):
93
85
        self.cmdQ = cmdQ
94
86
        self.lineQ = lineQ
95
 
        self.stdout = StdoutToWeb(self.cmdQ, self.lineQ)
 
87
        self.stdout = None
96
88
        Thread.__init__(self)
97
89
 
98
90
    def execCmd(self, cmd):
99
91
        try:
100
92
            sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
 
93
            self.stdout = StdoutToWeb(self.cmdQ, self.lineQ)
101
94
            sys.stdout = self.stdout
102
95
            sys.stderr = self.stdout
103
96
            res = eval(cmd, self.globs, self.locls)