From f6cc7ae495cd247778ab3861c3d3b64cdffd8fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 12 Jul 2018 15:55:26 +0200 Subject: [PATCH] Refactor ZMQWSProxy.__init__ --- .../networking/server/zmq_websocket_proxy.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/tfw/networking/server/zmq_websocket_proxy.py b/lib/tfw/networking/server/zmq_websocket_proxy.py index 85d6c60..3fc5bff 100644 --- a/lib/tfw/networking/server/zmq_websocket_proxy.py +++ b/lib/tfw/networking/server/zmq_websocket_proxy.py @@ -16,8 +16,14 @@ class ZMQWebSocketProxy(WebSocketHandler): def initialize(self, **kwargs): # pylint: disable=arguments-differ self._event_handler_connector = kwargs['event_handler_connector'] - self._message_handlers = kwargs.get('message_handlers', []) - self._proxy_filters = kwargs.get('proxy_filters', []) + + self.init_callback_lists_from( + kwargs, + [ + 'message_handlers', + 'proxy_filters' + ] + ) self.proxy_eventhandler_to_websocket = TFWProxy( self.send_eventhandler_message, @@ -28,7 +34,21 @@ class ZMQWebSocketProxy(WebSocketHandler): self.send_eventhandler_message ) - proxies = (self.proxy_eventhandler_to_websocket, self.proxy_websocket_to_eventhandler) + self.subscribe_proxy_callbacks() + + def init_callback_lists_from(self, init_kwargs, callback_lists): + for callback_list in callback_lists: + setattr( + self, + f'_{callback_list}', + init_kwargs.get(callback_list, []) + ) + + def subscribe_proxy_callbacks(self): + proxies = ( + self.proxy_eventhandler_to_websocket, + self.proxy_websocket_to_eventhandler + ) for proxy in proxies: proxy.proxy_filters.subscribe_callbacks(*self._proxy_filters) proxy.proxy_callbacks.subscribe_callbacks(*self._message_handlers)