X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/9c40f2f2d207eac67ca6add337ab5808deedea84..d6dfd46ed31d985e364b9ea9a404c394f15c2348:/pymindaemon.py diff --git a/pymindaemon.py b/pymindaemon.py index 98ced48..b440c52 100644 --- a/pymindaemon.py +++ b/pymindaemon.py @@ -33,7 +33,7 @@ class PyminDaemon(eventloop.EventLoop): >>> PyminDaemon(('', 9999), dict(test=test_handler)).run() """ - def __init__(self, bind_addr, routes): + def __init__(self, routes=dict(), bind_addr=('', 9999)): r"""Initialize the PyminDaemon object. See PyminDaemon class documentation for more info. @@ -65,11 +65,16 @@ class PyminDaemon(eventloop.EventLoop): if result is not None: result = serializer.serialize(result) response = u'OK ' + except dispatcher.Error, e: + result = unicode(e) + u'\n' + response = u'ERROR ' except Exception, e: - result = unicode(e) + import traceback + result = u'Internal server error\n' + traceback.print_exc() # TODO logging! response = u'ERROR ' if result is None: - response += u'0' + response += u'0\n' else: response += u'%d\n%s' % (len(result), result) self.file.sendto(response, addr) @@ -83,16 +88,14 @@ class PyminDaemon(eventloop.EventLoop): if __name__ == '__main__': - from dispatcher import handler - - @handler + @handler(u"Print all the arguments, return nothing.") def test_handler(*args): print 'test:', args - @handler + @handler(u"Echo the message passed as argument.") def echo_handler(message): print 'echo:', message return message - PyminDaemon(('', 9999), dict(test=test_handler, echo=echo_handler)).run() + PyminDaemon(dict(test=test_handler, echo=echo_handler)).run()