mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
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.
This commit is contained in:
parent
ae41c08fec
commit
c004f042f9
1 changed files with 13 additions and 0 deletions
|
@ -185,6 +185,19 @@ class basexmpp(object):
|
||||||
self.event_handlers[name] = []
|
self.event_handlers[name] = []
|
||||||
self.event_handlers[name].append((pointer, threaded, disposable))
|
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
|
def event(self, name, eventdata = {}): # called on an event
|
||||||
for handler in self.event_handlers.get(name, []):
|
for handler in self.event_handlers.get(name, []):
|
||||||
if handler[1]: #if threaded
|
if handler[1]: #if threaded
|
||||||
|
|
Loading…
Reference in a new issue