diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-06-07 14:12:19 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-06-22 03:01:02 +0200 |
commit | 833cccb188967948bc786fa6e9385821f8676362 (patch) | |
tree | ba99984b58d8f12ea43190137cbfda1bdf52de0e /poezio/plugin_manager.py | |
parent | d35256ccc9cd205aa72a5599ab25db7cd7263527 (diff) | |
download | poezio-833cccb188967948bc786fa6e9385821f8676362.tar.gz poezio-833cccb188967948bc786fa6e9385821f8676362.tar.bz2 poezio-833cccb188967948bc786fa6e9385821f8676362.tar.xz poezio-833cccb188967948bc786fa6e9385821f8676362.zip |
Rework priority handling for events
Introduce the concept of priority for event handlers, instead of the
position parameter.
The new `priority` parameter replacing `position` should be an integer
between 0 and 100. It defaults to 50.
The previous `position` parameter was only used to insert at a certain
position in the list of handlers (for this particular event). No
reference of it was kept, which means that it was not possible to ensure
an event was called in the position is was supposed to be.
I am now using per-event dicts, containing priority buckets (lists) of
handlers. I am using OrderedDicts to make it easier to loop through all
of the handlers, as insertion happens less often than reading.
I was also suggested using bisect with a simple list of tuples
(priority, handler) per event, but bisect tries to compare bound
methods, which is obviously not possible. Maybe it would be interesting
to find a way use this method instead of OrderedDict as that might be
less resource consuming.
This said, I don't think this part of poezio is a bottleneck at all, so
maybe this is just fine as is.
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'poezio/plugin_manager.py')
-rw-r--r-- | poezio/plugin_manager.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/poezio/plugin_manager.py b/poezio/plugin_manager.py index 89849747..8275e6f9 100644 --- a/poezio/plugin_manager.py +++ b/poezio/plugin_manager.py @@ -253,7 +253,7 @@ class PluginManager: if key in self.core.key_func: del self.core.commands[key] - def add_event_handler(self, module_name, event_name, handler, position=0): + def add_event_handler(self, module_name, event_name, handler, *args, **kwargs): """ Add an event handler. If event_name isn’t in the event list, assume it is a slixmpp event. @@ -261,7 +261,7 @@ class PluginManager: eh = self.event_handlers[module_name] eh.append((event_name, handler)) if event_name in self.core.events.events: - self.core.events.add_event_handler(event_name, handler, position) + self.core.events.add_event_handler(event_name, handler, *args, **kwargs) else: self.core.xmpp.add_event_handler(event_name, handler) |