summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-05-20 23:17:22 +0800
committerThom Nichols <tmnichols@gmail.com>2010-06-01 22:07:50 +0800
commit56b5cbe5b1a283745accadb59275b51b0c2dd9bb (patch)
tree54ca91aa2b05f70ed5becfb31562742290b3754e /sleekxmpp
parentde4d611d3053f2c4fb5029ba5214996cf3821e02 (diff)
downloadslixmpp-56b5cbe5b1a283745accadb59275b51b0c2dd9bb.tar.gz
slixmpp-56b5cbe5b1a283745accadb59275b51b0c2dd9bb.tar.bz2
slixmpp-56b5cbe5b1a283745accadb59275b51b0c2dd9bb.tar.xz
slixmpp-56b5cbe5b1a283745accadb59275b51b0c2dd9bb.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.py13
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