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

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