32 """ |
32 """ |
33 Yield available input. |
33 Yield available input. |
34 """ |
34 """ |
35 |
35 |
36 return self.filter(self.parser(self.source)) |
36 return self.filter(self.parser(self.source)) |
|
37 |
|
38 def fileno (self) : |
|
39 return self.source.fileno() |
37 |
40 |
38 def poll (self, poll=None) : |
41 def poll (self, poll=None, reading=(), writing=()) : |
39 """ |
42 """ |
40 Poll our source for input, with given polling behaviour: |
43 Poll our source for input, with given polling behaviour: |
41 True - select() on source |
44 True - select() on source |
42 False - peek on source |
45 False - peek on source |
43 float - timeout in seconds |
46 float - timeout in seconds |
|
47 |
|
48 Returns None on unknown, empty sequence on timeout, list of readables on select. |
|
49 """ |
|
50 |
|
51 # from __init__ |
|
52 if poll is None : |
|
53 poll = self._poll |
44 |
54 |
45 Returns True if we have input waiting, False on timeout with no input. None on indeterminate. |
|
46 """ |
|
47 |
|
48 reading = writing = () |
|
49 |
|
50 if poll is True : |
55 if poll is True : |
51 timeout = None # block |
56 timeout = None # block |
52 reading += (self.source, ) # file-like object with fileno() |
57 reading += (self, ) # source.fileno() |
53 |
58 |
54 elif not poll : |
59 elif not poll : |
55 timeout = 0.0 # do not block |
60 timeout = 0.0 # do not block |
56 |
61 |
57 else : |
62 else : |
58 timeout = float(poll) |
63 timeout = float(poll) |
59 |
64 |
60 log.debug("%s", timeout) |
65 log.debug("%s (%s)", reading, timeout) |
61 |
66 |
62 # select |
67 # select |
63 readable, writeable, ex = select.select(reading, writing, [], timeout) |
68 readable, writeable, ex = select.select(reading, writing, [], timeout) |
|
69 |
|
70 log.debug("select: %s", readable) |
64 |
71 |
65 if readable : |
72 if readable : |
66 return True |
73 return readable |
67 |
74 |
68 elif reading : |
75 elif reading : |
69 # timeout |
76 # timeout |
70 return False |
77 # XXX: this is the same as readable |
|
78 return () |
71 |
79 |
72 else : |
80 else : |
73 # unknown |
81 # unknown |
74 return None |
82 return None |
75 |
83 |