Move message validation code to where it belongs

This commit is contained in:
Kristóf Tóth 2018-06-29 12:06:08 +02:00
parent 36a86b0454
commit b217ac59c8
3 changed files with 7 additions and 8 deletions

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft. # Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details. # 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 .zmq_connector_base import ZMQConnectorBase
# from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved # from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved
from .message_sender import MessageSender from .message_sender import MessageSender

View File

@ -25,11 +25,6 @@ import json
from functools import wraps from functools import wraps
def validate_message(message):
if 'key' not in message:
raise ValueError('Invalid TFW message format!')
def serialize_tfw_msg(message): def serialize_tfw_msg(message):
""" """
Create TFW multipart data from message dict Create TFW multipart data from message dict

View File

@ -5,7 +5,6 @@ import json
from tornado.websocket import WebSocketHandler from tornado.websocket import WebSocketHandler
from tfw.networking import validate_message
from tfw.mixins import CallbackMixin from tfw.mixins import CallbackMixin
from tfw.config.logs import logging from tfw.config.logs import logging
@ -20,13 +19,18 @@ class TFWProxy:
self.proxy_filters = CallbackMixin() self.proxy_filters = CallbackMixin()
self.proxy_callbacks = CallbackMixin() self.proxy_callbacks = CallbackMixin()
self.proxy_filters.subscribe_callback(validate_message) self.proxy_filters.subscribe_callback(self.validate_message)
self.keyhandlers = { self.keyhandlers = {
'mirror': self.mirror, 'mirror': self.mirror,
'broadcast': self.broadcast 'broadcast': self.broadcast
} }
@staticmethod
def validate_message(message):
if 'key' not in message:
raise ValueError('Invalid TFW message format!')
def __call__(self, message): def __call__(self, message):
try: try:
self.proxy_filters._execute_callbacks(message) self.proxy_filters._execute_callbacks(message)