mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 01:47:16 +00:00
Implement helper to get all EventHandler instances in a given stack frame
This commit is contained in:
parent
015d8f4355
commit
0771a068e0
@ -2,6 +2,7 @@
|
||||
# All Rights Reserved. See LICENSE file for details.
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from inspect import currentframe
|
||||
|
||||
from tfw.networking.event_handlers import ServerConnector
|
||||
from tfw.crypto import message_checksum, KeyManager, verify_message
|
||||
@ -105,6 +106,18 @@ class EventHandlerBase(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_local_instances(cls):
|
||||
frame = currentframe()
|
||||
if frame is None:
|
||||
raise EnvironmentError('inspect.currentframe() is not supported!')
|
||||
|
||||
locals_values = frame.f_back.f_locals.values()
|
||||
return {
|
||||
instance for instance in locals_values
|
||||
if isinstance(instance, cls)
|
||||
}
|
||||
|
||||
|
||||
class FSMAwareEventHandler(EventHandlerBase, ABC):
|
||||
# pylint: disable=abstract-method
|
||||
|
Loading…
Reference in New Issue
Block a user