From 8b9f7e50cbd42b7947840275c791dd6b72cf5dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 14:46:00 +0100 Subject: [PATCH] Move FSM instantiation out of FSMManagingSocketHandler --- lib/tfw/networking/server/zmq_websocket_handler.py | 8 ++------ src/app/app.py | 10 +++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index aa55382..3262f2a 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -41,12 +41,8 @@ class ZMQWebSocketHandler(WebSocketHandler): class FSMManagingSocketHandler(ZMQWebSocketHandler): - fsm = None - - def __init__(self, FSM, application, request, **kwargs): - super().__init__(application, request, **kwargs) - if self.fsm is None: - FSMManagingSocketHandler.fsm = FSM() + def initialize(self, fsm): + self.fsm = fsm self.fsm.subscribe_message_handler(self.handle_fsm_message) def on_close(self): diff --git a/src/app/app.py b/src/app/app.py index 2ab1ea7..d6140a0 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -4,21 +4,17 @@ import zmq from tornado.web import Application from tornado.ioloop import IOLoop +from sql_injection_fsm import SQLInjectionFSM from tfw.config import WEB_PORT from tfw.config.logs import logging log = logging.getLogger(__name__) from tfw.networking.server.zmq_websocket_handler import FSMManagingSocketHandler -from sql_injection_fsm import SQLInjectionFSM - - -class SQLInjectionFSMManagingSocketHandler(FSMManagingSocketHandler): - def __init__(self, application, request, **kwargs): - super().__init__(SQLInjectionFSM, application, request, **kwargs) if __name__ == '__main__': + fsm = SQLInjectionFSM() routes = [ - (r'/ws', SQLInjectionFSMManagingSocketHandler), + (r'/ws', FSMManagingSocketHandler, {'fsm': fsm}), ] application = Application( routes,