mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 12:22:54 +00:00 
			
		
		
		
	Refactor FSMAware part from FSMAwareEH to a separate class
This commit is contained in:
		@@ -106,25 +106,17 @@ class EventHandlerBase(ABC):
 | 
				
			|||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FSMAwareEventHandler(EventHandlerBase, ABC):
 | 
					class FSMAware:
 | 
				
			||||||
    # pylint: disable=abstract-method
 | 
					    def __init__(self):
 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    Abstract base class for EventHandlers which automatically
 | 
					 | 
				
			||||||
    keep track of the state of the TFW FSM.
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    def __init__(self, key):
 | 
					 | 
				
			||||||
        super().__init__(key)
 | 
					 | 
				
			||||||
        self.subscribe('fsm_update')
 | 
					 | 
				
			||||||
        self.fsm_state = None
 | 
					        self.fsm_state = None
 | 
				
			||||||
        self.in_accepted_state = False
 | 
					        self.in_accepted_state = False
 | 
				
			||||||
        self._auth_key = KeyManager().auth_key
 | 
					        self._auth_key = KeyManager().auth_key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def dispatch_handling(self, message):
 | 
					    def update_fsm_data(self, message):
 | 
				
			||||||
        if message['key'] == 'fsm_update':
 | 
					        if message['key'] == 'fsm_update' and verify_message(self._auth_key, message):
 | 
				
			||||||
            if verify_message(self._auth_key, message):
 | 
					            self._handle_fsm_update(message)
 | 
				
			||||||
                self._handle_fsm_update(message)
 | 
					            return True
 | 
				
			||||||
            return None
 | 
					        return False
 | 
				
			||||||
        return super().dispatch_handling(message)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _handle_fsm_update(self, message):
 | 
					    def _handle_fsm_update(self, message):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
@@ -144,6 +136,23 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
 | 
				
			|||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class FSMAwareEventHandler(EventHandlerBase, FSMAware, ABC):
 | 
				
			||||||
 | 
					    # pylint: disable=abstract-method
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Abstract base class for EventHandlers which automatically
 | 
				
			||||||
 | 
					    keep track of the state of the TFW FSM.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    def __init__(self, key):
 | 
				
			||||||
 | 
					        EventHandlerBase.__init__(self, key)
 | 
				
			||||||
 | 
					        FSMAware.__init__(self)
 | 
				
			||||||
 | 
					        self.subscribe('fsm_update')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def dispatch_handling(self, message):
 | 
				
			||||||
 | 
					        if self.update_fsm_data(message):
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        return super().dispatch_handling(message)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BroadcastingEventHandler(EventHandlerBase, ABC):
 | 
					class BroadcastingEventHandler(EventHandlerBase, ABC):
 | 
				
			||||||
    # pylint: disable=abstract-method
 | 
					    # pylint: disable=abstract-method
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user