DebugClients/Python/AsyncIO.py

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a base class of an asynchronous interface for the debugger.
8 """
9
10
11 class AsyncIO(object):
12 """
13 Class implementing asynchronous reading and writing.
14 """
15 def __init__(self):
16 """
17 Constructor
18
19 @param parent the optional parent of this object (QObject) (ignored)
20 """
21 # There is no connection yet.
22 self.disconnect()
23
24 def disconnect(self):
25 """
26 Public method to disconnect any current connection.
27 """
28 self.readfd = None
29 self.writefd = None
30
31 def setDescriptors(self,rfd,wfd):
32 """
33 Public method called to set the descriptors for the connection.
34
35 @param rfd file descriptor of the input file (int)
36 @param wfd file descriptor of the output file (int)
37 """
38 self.rbuf = ''
39 self.readfd = rfd
40
41 self.wbuf = ''
42 self.writefd = wfd
43
44 def readReady(self,fd):
45 """
46 Public method called when there is data ready to be read.
47
48 @param fd file descriptor of the file that has data to be read (int)
49 """
50 try:
51 got = self.readfd.readline_p()
52 except:
53 return
54
55 if len(got) == 0:
56 self.sessionClose()
57 return
58
59 self.rbuf = self.rbuf + got
60
61 # Call handleLine for the line if it is complete.
62 eol = self.rbuf.find('\n')
63
64 while eol >= 0:
65 s = self.rbuf[:eol + 1]
66 self.rbuf = self.rbuf[eol + 1:]
67 self.handleLine(s)
68 eol = self.rbuf.find('\n')
69
70 def writeReady(self,fd):
71 """
72 Public method called when we are ready to write data.
73
74 @param fd file descriptor of the file that has data to be written (int)
75 """
76 self.writefd.write(self.wbuf)
77 self.writefd.flush()
78 self.wbuf = ''
79
80 def write(self,s):
81 """
82 Public method to write a string.
83
84 @param s the data to be written (string)
85 """
86 self.wbuf = self.wbuf + s

eric ide

mercurial