mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 11:09:56 +00:00
Fix del_event_handler for Python3 (different semantics for filter()).
Fixes issue #103
This commit is contained in:
parent
0b83edf439
commit
262da78ca7
2 changed files with 26 additions and 2 deletions
|
@ -840,8 +840,9 @@ class XMLStream(object):
|
|||
def filter_pointers(handler):
|
||||
return handler[0] != pointer
|
||||
|
||||
self.__event_handlers[name] = filter(filter_pointers,
|
||||
self.__event_handlers[name])
|
||||
self.__event_handlers[name] = list(filter(
|
||||
filter_pointers,
|
||||
self.__event_handlers[name]))
|
||||
|
||||
def event_handled(self, name):
|
||||
"""
|
||||
|
|
|
@ -48,6 +48,29 @@ class TestEvents(SleekTest):
|
|||
msg = "Event was not triggered the correct number of times: %s"
|
||||
self.failUnless(happened == [True], msg % happened)
|
||||
|
||||
def testAddDelAddEvent(self):
|
||||
"""Test adding, then removing, then adding an event handler."""
|
||||
happened = []
|
||||
|
||||
def handletestevent(event):
|
||||
happened.append(True)
|
||||
|
||||
self.xmpp.add_event_handler("test_event", handletestevent)
|
||||
self.xmpp.event("test_event", {})
|
||||
|
||||
self.xmpp.del_event_handler("test_event", handletestevent)
|
||||
# Should not trigger because it was deleted
|
||||
self.xmpp.event("test_event", {})
|
||||
|
||||
self.xmpp.add_event_handler("test_event", handletestevent)
|
||||
self.xmpp.event("test_event", {})
|
||||
|
||||
# Give the event queue time to process.
|
||||
time.sleep(0.1)
|
||||
|
||||
msg = "Event was not triggered the correct number of times: %s"
|
||||
self.failUnless(happened == [True, True], msg % happened)
|
||||
|
||||
def testDisposableEvent(self):
|
||||
"""Test disposable handler working, then not being triggered again."""
|
||||
happened = []
|
||||
|
|
Loading…
Reference in a new issue