summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/base/app_manager.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index ec42f97f..821a4b5c 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -176,13 +176,28 @@ class RyuApp(object):
observers.pop(name, None)
def get_handlers(self, ev, state=None):
- handlers = self.event_handlers.get(ev.__class__, [])
+ """Returns a list of handlers for the specific event.
+
+ :param ev: The event to handle.
+ :param state: The current state. ("dispatcher")
+ If None is given, returns all handlers for the event.
+ Otherwise, returns only handlers that are interested
+ in the specified state.
+ The default is None.
+ """
+ ev_cls = ev.__class__
+ handlers = self.event_handlers.get(ev_cls, [])
if state is None:
return handlers
- dispatchers = lambda x: x.callers[ev.__class__].dispatchers
- return [handler for handler in handlers
- if not dispatchers(handler) or state in dispatchers(handler)]
+ def test(h):
+ states = h.callers[ev_cls].dispatchers
+ if not states:
+ # empty states means all states
+ return True
+ return state in states
+
+ return filter(test, handlers)
def get_observers(self, ev, state):
observers = []