def handle(self):
r"handle() -> None :: Handle incoming events using the dispatcher."
(msg, addr) = self.file.recvfrom(65535)
- result = self.dispatcher.dispatch(msg)
+ try:
+ result = self.dispatcher.dispatch(msg)
+ response = 'OK '
+ except Exception, e:
+ result = str(e)
+ response = 'ERROR '
if result is None:
- msg = 'OK 0'
+ response += '0'
else:
- msg = 'OK %d\n%s' % (len(str(result)), result)
- self.file.sendto(msg, addr)
- #try:
- # d.dispatch(msg)
- #except dis.BadRouteError, inst:
- # sock.sendto('Bad route from : ' + inst.cmd + '\n', addr)
- #except dis.CommandNotFoundError, inst:
- # sock.sendto('Command not found : ' + inst.cmd + '\n', addr)
+ response += '%d\n%s' % (len(str(result)), result)
+ self.file.sendto(response, addr)
def run(self):
r"run() -> None :: Run the event loop (shortcut to loop())"
if __name__ == '__main__':
+ @handler
def test_handler(*args):
print 'test:', args