From: Leandro Lucarella Date: Mon, 24 Sep 2007 17:11:33 +0000 (-0300) Subject: Add a simple response to all commands. X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/b33b3ccf6aedaec3d33968d126131e3690319b90?ds=inline;hp=-c Add a simple response to all commands. The response consist of a success indicator ("OK") followed by the response body lenght. The response body is command-dependant. --- b33b3ccf6aedaec3d33968d126131e3690319b90 diff --git a/dispatcher.py b/dispatcher.py index addd45f..29cff6e 100644 --- a/dispatcher.py +++ b/dispatcher.py @@ -108,7 +108,7 @@ class Dispatcher: raise CommandNotFoundError(command) handler = getattr(handler, route[0]) route = route[1:] - handler(*route) + return handler(*route) if __name__ == '__main__': diff --git a/pymindaemon.py b/pymindaemon.py index 76a31d7..1e9589a 100644 --- a/pymindaemon.py +++ b/pymindaemon.py @@ -58,7 +58,12 @@ 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) + result = self.dispatcher.dispatch(msg) + if result is None: + msg = 'OK 0' + else: + msg = 'OK %d\n%s' % (len(str(result)), result) + self.file.sendto(msg, addr) #try: # d.dispatch(msg) #except dis.BadRouteError, inst: