mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 03:01:56 +00:00
Refactor ZMQWSProxy.__init__
This commit is contained in:
parent
da98576260
commit
f6cc7ae495
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user