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

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: drtomc
  • Date: 2008-03-06 03:09:14 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:660
console: buffering now tries to buffer enough, but not too much.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        self.remainder = ''
59
59
 
60
60
    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
 
61
        self.remainder = self.remainder + stuff
 
62
 
 
63
        # if there's less than 128 bytes, buffer
 
64
        if len(self.remainder) < 128:
64
65
            return
65
66
 
66
 
        # Split the content up into lines, and ship all the completed
67
 
        # lines off to the server.
68
 
        lines = stuff.split("\n")
69
 
        lines[0] = self.remainder + lines[0]
 
67
        # if there's lots, then send it in 1/2K blocks
 
68
        while len(self.remainder) > 512:
 
69
            blk = self.remainder[0:512]
 
70
            self.cmdQ.put({"output":blk})
 
71
            expiry.ping()
 
72
            ln = self.lineQ.get()
 
73
            self.remainder = self.remainder[512:]
 
74
 
 
75
        # Finally, split the remainder up into lines, and ship all the
 
76
        # completed lines off to the server.
 
77
        lines = self.remainder.split("\n")
70
78
        self.remainder = lines[-1]
71
79
        del lines[-1]
72
80