本文整理汇总了Python中twisted.words.xish.utility.EventDispatcher.addOnetimeObserver方法的典型用法代码示例。如果您正苦于以下问题:Python EventDispatcher.addOnetimeObserver方法的具体用法?Python EventDispatcher.addOnetimeObserver怎么用?Python EventDispatcher.addOnetimeObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.xish.utility.EventDispatcher
的用法示例。
在下文中一共展示了EventDispatcher.addOnetimeObserver方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testOnetimeDispatch
# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import addOnetimeObserver [as 别名]
def testOnetimeDispatch(self):
d = EventDispatcher()
msg = Element(("ns", "message"))
cb = CallbackTracker()
d.addOnetimeObserver("/message", cb.call)
d.dispatch(msg)
self.assertEquals(cb.called, 1)
d.dispatch(msg)
self.assertEquals(cb.called, 1)
示例2: test_cleanUpOnetimeEventObserver
# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import addOnetimeObserver [as 别名]
def test_cleanUpOnetimeEventObserver(self):
"""
Test observer clean-up after onetime named events.
"""
d = EventDispatcher()
cb = CallbackTracker()
d.addOnetimeObserver('//event/test', cb.call)
d.dispatch(None, '//event/test')
self.assertEqual(1, cb.called)
self.assertEqual(0, len(d._eventObservers.pop(0)))
示例3: test_cleanUpOnetimeXPathObserver
# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import addOnetimeObserver [as 别名]
def test_cleanUpOnetimeXPathObserver(self):
"""
Test observer clean-up after onetime XPath events.
"""
d = EventDispatcher()
cb = CallbackTracker()
msg = Element((None, "message"))
d.addOnetimeObserver('/message', cb.call)
d.dispatch(msg)
self.assertEqual(1, cb.called)
self.assertEqual(0, len(d._xpathObservers.pop(0)))
示例4: test_addOnetimeObserverInDispatch
# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import addOnetimeObserver [as 别名]
def test_addOnetimeObserverInDispatch(self):
"""
Test for registration of a onetime observer during dispatch.
"""
d = EventDispatcher()
msg = Element(("ns", "message"))
cb = CallbackTracker()
def onMessage(msg):
d.addOnetimeObserver("/message", cb.call)
d.addOnetimeObserver("/message", onMessage)
d.dispatch(msg)
self.assertEquals(cb.called, 0)
d.dispatch(msg)
self.assertEquals(cb.called, 1)
d.dispatch(msg)
self.assertEquals(cb.called, 1)