Integrate ABC module where we have abstract classes

This commit is contained in:
Kristóf Tóth 2018-03-27 17:49:32 +02:00
parent 6bd0ba1450
commit 43c46a7af2
2 changed files with 10 additions and 4 deletions

View File

@ -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

View File

@ -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