From f3b3982a0e53b1ff2cfc7fa9c3288e3156bfdd55 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 3 Sep 2013 15:51:54 +0200 Subject: Fix Exception use --- changes/bug-fix-exception | 1 + src/leap/common/events/client.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changes/bug-fix-exception diff --git a/changes/bug-fix-exception b/changes/bug-fix-exception new file mode 100644 index 0000000..866c39a --- /dev/null +++ b/changes/bug-fix-exception @@ -0,0 +1 @@ + o Correct use of CallbackAlreadyRegistered exception diff --git a/src/leap/common/events/client.py b/src/leap/common/events/client.py index 4ae9bff..816cec1 100644 --- a/src/leap/common/events/client.py +++ b/src/leap/common/events/client.py @@ -120,7 +120,7 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None, cbklist = registered_callbacks[signal] if uid and filter(lambda (x, y): x == uid, cbklist): if not replace: - raise CallbackAlreadyRegisteredException() + raise CallbackAlreadyRegistered() else: registered_callbacks[signal] = filter(lambda(x, y): x != uid, cbklist) -- cgit v1.2.3 From 21b7235a4368c6681f2788893dd5073c9fffd37d Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 3 Sep 2013 15:52:39 +0200 Subject: cosmetic changes to imports --- src/leap/common/events/client.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/leap/common/events/client.py b/src/leap/common/events/client.py index 816cec1..ff1f52a 100644 --- a/src/leap/common/events/client.py +++ b/src/leap/common/events/client.py @@ -14,7 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - """ The client end point of the events mechanism. @@ -27,18 +26,15 @@ server that it wants to be notified whenever signals of that type are sent by some other client. """ - import logging -import threading from protobuf.socketrpc import RpcService -from leap.common.events import ( - events_pb2 as proto, - server, - daemon, - mac_auth, -) + +from leap.common.events import events_pb2 as proto +from leap.common.events import server +from leap.common.events import daemon +from leap.common.events import mac_auth logger = logging.getLogger(__name__) @@ -118,6 +114,10 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None, if signal not in registered_callbacks: registered_callbacks[signal] = [] cbklist = registered_callbacks[signal] + + # TODO should check that the callback has the right + # number of arguments. + if uid and filter(lambda (x, y): x == uid, cbklist): if not replace: raise CallbackAlreadyRegistered() -- cgit v1.2.3 From 2c2f1eb7714bf98059b6966e08d01897c5626bd4 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 3 Sep 2013 15:53:04 +0200 Subject: change verbosity level in logging --- src/leap/common/events/client.py | 11 ++++++----- src/leap/common/events/server.py | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/leap/common/events/client.py b/src/leap/common/events/client.py index ff1f52a..83f18e0 100644 --- a/src/leap/common/events/client.py +++ b/src/leap/common/events/client.py @@ -133,12 +133,13 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None, request.mac = "" service = RpcService(proto.EventsServerService_Stub, server.SERVER_PORT, 'localhost') - logger.info( + logger.debug( "Sending registration request to server on port %s: %s", server.SERVER_PORT, str(request)[:40]) return service.register(request, callback=reqcbk, timeout=timeout) + def unregister(signal, uid=None, reqcbk=None, timeout=1000): """ Unregister a callback. @@ -226,7 +227,7 @@ def signal(signal, content="", mac_method="", mac="", reqcbk=None, request.mac = mac service = RpcService(proto.EventsServerService_Stub, server.SERVER_PORT, 'localhost') - logger.info("Sending signal to server: %s", str(request)[:40]) + logger.debug("Sending signal to server: %s", str(request)[:40]) return service.signal(request, callback=reqcbk, timeout=timeout) @@ -251,7 +252,7 @@ def ping(port, reqcbk=None, timeout=1000): proto.EventsClientService_Stub, port, 'localhost') - logger.info("Pinging a client in port %d..." % port) + logger.debug("Pinging a client in port %d..." % port) return service.ping(request, callback=reqcbk, timeout=timeout) @@ -277,7 +278,7 @@ class EventsClientService(proto.EventsClientService): :param done: callback to be called when done :type done: protobuf.socketrpc.server.Callback """ - logger.info('Received signal from server: %s...' % str(request)[:40]) + logger.debug('Received signal from server: %s...' % str(request)[:40]) # run registered callbacks # TODO: verify authentication using mac in incoming message @@ -303,7 +304,7 @@ class EventsClientService(proto.EventsClientService): :param done: callback to be called when done :type done: protobuf.socketrpc.server.Callback """ - logger.info("Received ping request, sending response.") + logger.debug("Received ping request, sending response.") response = proto.EventResponse() response.status = proto.EventResponse.OK done.run(response) diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py index 861cb4f..dc55551 100644 --- a/src/leap/common/events/server.py +++ b/src/leap/common/events/server.py @@ -85,6 +85,7 @@ def ensure_server(port=SERVER_PORT): logger.info('Launching server on port %d.', port) return EventsServerDaemon.ensure(port) + def process_ping(port, request, response): """ Response callback for the ping event. @@ -100,7 +101,7 @@ def process_ping(port, request, response): logger.info('A server is already running on port %d.', port) return # port is taken, and not by an events server - logger.info('Port %d is taken by something not an events server.', port) + logger.warning('Port %d is taken by something not an events server.', port) raise PortAlreadyTaken(port) @@ -125,7 +126,7 @@ def ping(port=SERVER_PORT, reqcbk=None, timeout=1000): proto.EventsServerService_Stub, port, 'localhost') - logger.info("Pinging server in port %d..." % port) + logger.debug("Pinging server in port %d..." % port) return service.ping(request, callback=reqcbk, timeout=timeout) @@ -196,14 +197,14 @@ class EventsServerService(proto.EventsServerService): :param done: callback to be called when done :type done: protobuf.socketrpc.server.Callback """ - logger.info('Received signal from client: %s...', str(request)[:40]) + logger.debug('Received signal from client: %s...', str(request)[:40]) # send signal to all registered clients # TODO: verify signal auth if request.event in registered_clients: for port in registered_clients[request.event]: def callback(req, resp): - logger.info("Signal received by " + str(port)) + logger.debug("Signal received by " + str(port)) service = RpcService(proto.EventsClientService_Stub, port, 'localhost') @@ -224,7 +225,7 @@ class EventsServerService(proto.EventsServerService): :param done: callback to be called when done :type done: protobuf.socketrpc.server.Callback """ - logger.info("Received ping request, sending response.") + logger.debug("Received ping request, sending response.") response = proto.EventResponse() response.status = proto.EventResponse.OK done.run(response) -- cgit v1.2.3