X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/f2b9d4634807e38cec82fc1d2c4250b5e6106c5a..d6d7ebf986963fbf1d960730b7371ee5bbbf2952:/pymindaemon.py diff --git a/pymindaemon.py b/pymindaemon.py index 76a31d7..b8369b9 100644 --- a/pymindaemon.py +++ b/pymindaemon.py @@ -58,13 +58,17 @@ class PyminDaemon(EventLoop): def handle(self): r"handle() -> None :: Handle incoming events using the dispatcher." (msg, addr) = self.file.recvfrom(65535) - self.dispatcher.dispatch(msg) - #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) + try: + result = self.dispatcher.dispatch(msg) + response = 'OK ' + except Exception, e: + result = str(e) + response = 'ERROR ' + if result is None: + response += '0' + else: + 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())" @@ -75,6 +79,7 @@ class PyminDaemon(EventLoop): if __name__ == '__main__': + @handler def test_handler(*args): print 'test:', args