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


Python EventDispatcher.removeObserver方法代码示例

本文整理汇总了Python中twisted.words.xish.utility.EventDispatcher.removeObserver方法的典型用法代码示例。如果您正苦于以下问题:Python EventDispatcher.removeObserver方法的具体用法?Python EventDispatcher.removeObserver怎么用?Python EventDispatcher.removeObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.words.xish.utility.EventDispatcher的用法示例。


在下文中一共展示了EventDispatcher.removeObserver方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testStuff

# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import removeObserver [as 别名]
    def testStuff(self):
        d = EventDispatcher()
        cb1 = CallbackTracker()
        cb2 = CallbackTracker()
        cb3 = CallbackTracker()

        d.addObserver("/message/body", cb1.call)
        d.addObserver("/message", cb1.call)
        d.addObserver("/presence", cb2.call)
        d.addObserver("//event/testevent", cb3.call)

        msg = Element(("ns", "message"))
        msg.addElement("body")

        pres = Element(("ns", "presence"))
        pres.addElement("presence")

        d.dispatch(msg)
        self.assertEquals(cb1.called, 2)
        self.assertEquals(cb1.obj, msg)
        self.assertEquals(cb2.called, 0)

        d.dispatch(pres)
        self.assertEquals(cb1.called, 2)
        self.assertEquals(cb2.called, 1)
        self.assertEquals(cb2.obj, pres)
        self.assertEquals(cb3.called, 0)

        d.dispatch(d, "//event/testevent")
        self.assertEquals(cb3.called, 1)
        self.assertEquals(cb3.obj, d)

        d.removeObserver("/presence", cb2.call)
        d.dispatch(pres)
        self.assertEquals(cb2.called, 1)
开发者ID:Almad,项目名称:twisted,代码行数:37,代码来源:test_xishutil.py

示例2: test_cleanUpRemoveEventObserver

# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import removeObserver [as 别名]
    def test_cleanUpRemoveEventObserver(self):
        """
        Test observer clean-up after removeObserver for named events.
        """

        d = EventDispatcher()
        cb = CallbackTracker()

        d.addObserver('//event/test', cb.call)
        d.dispatch(None, '//event/test')
        self.assertEqual(1, cb.called)
        d.removeObserver('//event/test', cb.call)
        self.assertEqual(0, len(d._eventObservers.pop(0)))
开发者ID:Almad,项目名称:twisted,代码行数:15,代码来源:test_xishutil.py

示例3: test_cleanUpRemoveXPathObserver

# 需要导入模块: from twisted.words.xish.utility import EventDispatcher [as 别名]
# 或者: from twisted.words.xish.utility.EventDispatcher import removeObserver [as 别名]
    def test_cleanUpRemoveXPathObserver(self):
        """
        Test observer clean-up after removeObserver for XPath events.
        """

        d = EventDispatcher()
        cb = CallbackTracker()
        msg = Element((None, "message"))

        d.addObserver('/message', cb.call)
        d.dispatch(msg)
        self.assertEqual(1, cb.called)
        d.removeObserver('/message', cb.call)
        self.assertEqual(0, len(d._xpathObservers.pop(0)))
开发者ID:Almad,项目名称:twisted,代码行数:16,代码来源:test_xishutil.py


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