当前位置: 首页>>代码示例>>Python>>正文


Python EventDispatcher.addOnetimeObserver方法代码示例

本文整理汇总了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)
开发者ID:Almad,项目名称:twisted,代码行数:12,代码来源:test_xishutil.py

示例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)))
开发者ID:Almad,项目名称:twisted,代码行数:14,代码来源:test_xishutil.py

示例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)))
开发者ID:Almad,项目名称:twisted,代码行数:15,代码来源:test_xishutil.py

示例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)
开发者ID:Almad,项目名称:twisted,代码行数:23,代码来源:test_xishutil.py


注:本文中的twisted.words.xish.utility.EventDispatcher.addOnetimeObserver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。