mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 02:51:57 +00:00
Integrate ABC module where we have abstract classes
This commit is contained in:
parent
6bd0ba1450
commit
43c46a7af2
@ -1,8 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from tfw.networking.serialization import deserialize_all
|
||||
from tfw.networking.event_handlers.server_connector import ServerConnector
|
||||
|
||||
|
||||
class EventHandlerBase:
|
||||
class EventHandlerBase(ABC):
|
||||
def __init__(self, key):
|
||||
self.server_connector = ServerConnector()
|
||||
self.key = key
|
||||
@ -17,6 +19,7 @@ class EventHandlerBase:
|
||||
if response is None: return
|
||||
self.server_connector.send(key, response)
|
||||
|
||||
@abstractmethod
|
||||
def dispatch_handling(self, key, message):
|
||||
raise NotImplementedError
|
||||
|
||||
@ -24,6 +27,7 @@ class EventHandlerBase:
|
||||
if key != 'reset': return self.handle_event(key, message)
|
||||
else: return self.handle_reset(message)
|
||||
|
||||
@abstractmethod
|
||||
def handle_event(self, key, message):
|
||||
raise NotImplementedError
|
||||
|
||||
@ -58,12 +62,12 @@ class EventHandlerBase:
|
||||
self.subscriptions.clear()
|
||||
|
||||
|
||||
class TriggerlessEventHandler(EventHandlerBase):
|
||||
class TriggerlessEventHandler(EventHandlerBase, ABC):
|
||||
def dispatch_handling(self, key, message):
|
||||
return self._dispatch_handling(key, message)
|
||||
|
||||
|
||||
class TriggeredEventHandler(EventHandlerBase):
|
||||
class TriggeredEventHandler(EventHandlerBase, ABC):
|
||||
def __init__(self, key, trigger):
|
||||
super().__init__(key)
|
||||
self.trigger = trigger
|
||||
|
@ -1,4 +1,5 @@
|
||||
import json
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from tornado.websocket import WebSocketHandler
|
||||
|
||||
@ -9,7 +10,7 @@ from tfw.config.logs import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ZMQWebSocketHandler(WebSocketHandler):
|
||||
class ZMQWebSocketHandler(WebSocketHandler, ABC):
|
||||
_event_handler_connector = EventHandlerConnector()
|
||||
instances = set()
|
||||
|
||||
@ -45,6 +46,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
||||
LOG.debug('Received on WebSocket: %s', message)
|
||||
self.send_message(self.make_response(message))
|
||||
|
||||
@abstractmethod
|
||||
def make_response(self, message):
|
||||
raise NotImplementedError
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user