s = ''
while True:
s = self.rfh.read(1)
- if s == '': raise Exception
+ if s == '': raise Exception('nothing read!')
if s == '\n' or s == '\r':
state = 1
prefix = ''
self.challenge = int(prefix, 16)
return
- def get_response(self):
+ def get_response(self, async = False):
self.wfh.flush()
while True:
s = ''
text = s[4:]
if code in asynchronous_responses:
self.handle_event(code, text)
+ if async: return None
else:
self.await_prompt()
return (code, text)
return None
def wait_for_events(self, timeout = None):
+ if self.events: return True
(r, _, _) = select([self.rfh], [], [], timeout)
if not r: return False
event_added = False
while True:
- r.get_response()
+ self.get_response(async = True)
(r, _, _) = select([self.rfh], [], [], 0)
if not r: return event_added