From 14a62285f0f84886c55eabe7da325d332cfe9992 Mon Sep 17 00:00:00 2001 From: Laurens Van Houtven Date: Mon, 2 Mar 2009 12:24:40 +0100 Subject: [PATCH] net.py: typo fix + catch the right exception net.py previously didn't catch the right exception when calling the cleanup method on its handler. This missed our watchful eye because SequentialHandler, which is usually used, does handle it properly. 1. If it really didn't have such a method, the interpreter throws AttributeError, not NameError 2. If the handler inherits from BaseHandler (which it should) it should raise NotImplementedError. Signed-off-by: Laurens Van Houtven --- code/breadcrumb/server/net.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/code/breadcrumb/server/net.py b/code/breadcrumb/server/net.py index e61e61a..95046b7 100644 --- a/code/breadcrumb/server/net.py +++ b/code/breadcrumb/server/net.py @@ -42,7 +42,7 @@ class BreadcrumbServer: """Unpacks a new crumb, checks it, and passes it to the handler.""" logging.debug('Got a new crumb, sending to decoder...') - point = decoding.decodecrumb(packed) + point = decoding.decode_crumb(packed) if self.keepdatapoints: self.datapoints.append(point) @@ -60,10 +60,13 @@ class BreadcrumbServer: chance to close connections, finalize files... """ try: - logging.info('Cleaning up...') - self.handler.cleanup() - except NameError: - logging.info('... but the handler has no cleanup method.') + logging.info('Cleaning up (calling the clean_up method)...') + self.handler.clean_up() + except AttributeError: + logging.error('... but the handler has no cleanup method!') + logging.error('Does it inherit from BaseHandler properly?') + except NotImplementedError: + logging.debug("... but the handler didn't implement it.") class BreadcrumbTCPServer(BreadcrumbServer, Protocol): """A TCP server for the breadcrumb protocol.""" @@ -85,7 +88,7 @@ class BreadcrumbUDPServer(BreadcrumbServer, DatagramProtocol): logging.debug("received something from %s:%d" % (host, port)) self.new_crumb(crumb) -def start_server(port = None, handler = None, encap = 'UDP'): +def start_server(port = None, handler = None, encap = 'UDP', **kwargs): """Runs the Breadcrumb server. The server argument is either the server proper (for UDP servers) or the @@ -122,9 +125,6 @@ def start_server(port = None, handler = None, encap = 'UDP'): logging.debug("Prepared UDP reactor on port %d" % port) reactor.listenUDP(port, server) - elif encap == 'SSH': - # TODO: Implement - raise NotImplementedError, 'SSH protocol server not implemented.' else: raise RuntimeError, 'Unknown encapsulation %s' % encap -- 2.11.4.GIT