diff options
author | Lance Stout <lancestout@gmail.com> | 2010-05-20 23:17:22 +0800 |
---|---|---|
committer | Nathan Fritz <fritzy@netflint.net> | 2010-05-21 03:54:48 +0800 |
commit | c004f042f9976e90cfd42a0698ba83872fe00825 (patch) | |
tree | 336c46c3d518f0897450a9f2db4929ba7f8513d5 /sleekxmpp | |
parent | ae41c08fecfe627627f2a4d9b3861d4ae24d673e (diff) | |
download | slixmpp-c004f042f9976e90cfd42a0698ba83872fe00825.tar.gz slixmpp-c004f042f9976e90cfd42a0698ba83872fe00825.tar.bz2 slixmpp-c004f042f9976e90cfd42a0698ba83872fe00825.tar.xz slixmpp-c004f042f9976e90cfd42a0698ba83872fe00825.zip |
Added del_event_handler to remove handler functions for a given event.
All registered handlers for the event which use the given function will
be removed.
Using this method allows agents to reconfigure their behaviour on the fly
without needing to add extra state information to event handling functions.
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/basexmpp.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 13fe2100..83431bd7 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -185,6 +185,19 @@ class basexmpp(object): self.event_handlers[name] = [] self.event_handlers[name].append((pointer, threaded, disposable)) + def del_event_handler(self, name, pointer): + """Remove a handler for an event.""" + if not name in self.event_handlers: + return + + # Need to keep handlers that do not use + # the given function pointer + def filter_pointers(handler): + return handler[0] != pointer + + self.event_handlers[name] = filter(filter_pointers, + self.event_handlers[name]) + def event(self, name, eventdata = {}): # called on an event for handler in self.event_handlers.get(name, []): if handler[1]: #if threaded |