mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 07:41:56 +00:00
Replace homemade hacky defaultdict with defaultdict ¯\_(ツ)_/¯
This commit is contained in:
parent
5e9eb88bfc
commit
47a4e078de
@ -1,4 +1,5 @@
|
||||
from tornado.web import Application
|
||||
from collections import defaultdict
|
||||
|
||||
from tfw.networking.server.controller_responder import ControllerResponder
|
||||
from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
|
||||
@ -39,26 +40,19 @@ class TFWServer:
|
||||
class FSMManager:
|
||||
def __init__(self, fsm_type):
|
||||
self.fsm = fsm_type()
|
||||
self.trigger_handlers = {}
|
||||
self.trigger_handlers = defaultdict(list)
|
||||
|
||||
def trigger(self, trigger):
|
||||
self._prepare_handlerlist(trigger)
|
||||
if all((handler() for handler in self.trigger_handlers[trigger])):
|
||||
try: self.fsm.trigger(trigger, message='')
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
|
||||
def subscribe_handler(self, trigger, handler):
|
||||
self._prepare_handlerlist(trigger)
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
|
||||
def unsubscribe_handler(self, trigger, handler):
|
||||
self._prepare_handlerlist(trigger)
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
|
||||
def _prepare_handlerlist(self, trigger):
|
||||
try: self.trigger_handlers[trigger]
|
||||
except KeyError: self.trigger_handlers[trigger] = []
|
||||
|
||||
|
||||
class FSMUpdater:
|
||||
def __init__(self, fsm):
|
||||
|
Loading…
Reference in New Issue
Block a user