From b217ac59c82ca2b03d67c7e47579d5eca3dbc887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 29 Jun 2018 12:06:08 +0200 Subject: [PATCH] Move message validation code to where it belongs --- lib/tfw/networking/__init__.py | 2 +- lib/tfw/networking/serialization.py | 5 ----- lib/tfw/networking/server/zmq_websocket_handler.py | 8 ++++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/tfw/networking/__init__.py b/lib/tfw/networking/__init__.py index 0958f0b..c5879b7 100644 --- a/lib/tfw/networking/__init__.py +++ b/lib/tfw/networking/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from .serialization import serialize_tfw_msg, deserialize_tfw_msg, validate_message, with_deserialize_tfw_msg +from .serialization import serialize_tfw_msg, deserialize_tfw_msg, with_deserialize_tfw_msg from .zmq_connector_base import ZMQConnectorBase # from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved from .message_sender import MessageSender diff --git a/lib/tfw/networking/serialization.py b/lib/tfw/networking/serialization.py index 483b666..c28eec0 100644 --- a/lib/tfw/networking/serialization.py +++ b/lib/tfw/networking/serialization.py @@ -25,11 +25,6 @@ import json from functools import wraps -def validate_message(message): - if 'key' not in message: - raise ValueError('Invalid TFW message format!') - - def serialize_tfw_msg(message): """ Create TFW multipart data from message dict diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index 0bf82fb..508049f 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -5,7 +5,6 @@ import json from tornado.websocket import WebSocketHandler -from tfw.networking import validate_message from tfw.mixins import CallbackMixin from tfw.config.logs import logging @@ -20,13 +19,18 @@ class TFWProxy: self.proxy_filters = CallbackMixin() self.proxy_callbacks = CallbackMixin() - self.proxy_filters.subscribe_callback(validate_message) + self.proxy_filters.subscribe_callback(self.validate_message) self.keyhandlers = { 'mirror': self.mirror, 'broadcast': self.broadcast } + @staticmethod + def validate_message(message): + if 'key' not in message: + raise ValueError('Invalid TFW message format!') + def __call__(self, message): try: self.proxy_filters._execute_callbacks(message)