mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-14 16:27:16 +00:00
Move TFWRouter to separate file
This commit is contained in:
parent
42f959878f
commit
3fca555251
22
tfw/internals/server/tfw_router.py
Normal file
22
tfw/internals/server/tfw_router.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from tfw.internals.networking import Scope
|
||||||
|
|
||||||
|
|
||||||
|
class TFWRouter:
|
||||||
|
def __init__(self, send_to_zmq, send_to_websockets):
|
||||||
|
self.send_to_zmq = send_to_zmq
|
||||||
|
self.send_to_websockets = send_to_websockets
|
||||||
|
|
||||||
|
def route(self, message):
|
||||||
|
scope = Scope(message.pop('scope', 'zmq'))
|
||||||
|
|
||||||
|
routing_table = {
|
||||||
|
Scope.ZMQ: self.send_to_zmq,
|
||||||
|
Scope.WEBSOCKET: self.send_to_websockets,
|
||||||
|
Scope.BROADCAST: self.broadcast
|
||||||
|
}
|
||||||
|
action = routing_table[scope]
|
||||||
|
action(message)
|
||||||
|
|
||||||
|
def broadcast(self, message):
|
||||||
|
self.send_to_zmq(message)
|
||||||
|
self.send_to_websockets(message)
|
@ -3,7 +3,7 @@ import logging
|
|||||||
|
|
||||||
from tornado.websocket import WebSocketHandler
|
from tornado.websocket import WebSocketHandler
|
||||||
|
|
||||||
from tfw.internals.networking import Scope
|
from .tfw_router import TFWRouter
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -46,24 +46,3 @@ class ZMQWebSocketRouter(WebSocketHandler):
|
|||||||
# much secure, very cors, wow
|
# much secure, very cors, wow
|
||||||
def check_origin(self, origin):
|
def check_origin(self, origin):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class TFWRouter:
|
|
||||||
def __init__(self, send_to_zmq, send_to_websockets):
|
|
||||||
self.send_to_zmq = send_to_zmq
|
|
||||||
self.send_to_websockets = send_to_websockets
|
|
||||||
|
|
||||||
def route(self, message):
|
|
||||||
scope = Scope(message.pop('scope', 'zmq'))
|
|
||||||
|
|
||||||
routing_table = {
|
|
||||||
Scope.ZMQ: self.send_to_zmq,
|
|
||||||
Scope.WEBSOCKET: self.send_to_websockets,
|
|
||||||
Scope.BROADCAST: self.broadcast
|
|
||||||
}
|
|
||||||
action = routing_table[scope]
|
|
||||||
action(message)
|
|
||||||
|
|
||||||
def broadcast(self, message):
|
|
||||||
self.send_to_zmq(message)
|
|
||||||
self.send_to_websockets(message)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user