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


Python Element.addContent方法代码示例

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


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

示例1: makeDataElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
 def makeDataElement(self):
     """ Returns an XML Element that can be put into a jabber:x:avatar IQ stanza. """
     data = Element((None, "data"))
     data["mimetype"] = "image/png"
     data.addContent(
         base64.encodestring(self.getImageData()).replace("\n", ""))
     return data
开发者ID:2mf,项目名称:pyicqt,代码行数:9,代码来源:avatar.py

示例2: test_fromElement_bad

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_fromElement_bad(self):
        el = Element((None, 'note'))
        el['type'] = 'wrong'
        el.addContent('bla')
        n = Note.fromElement(el)

        self.assertEquals(n.note_type, 'warn')
        self.assertEquals(n.content, 'bla')
开发者ID:wyn,项目名称:collab,代码行数:10,代码来源:commandTests.py

示例3: test_fromElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_fromElement(self):
        el = Element((None, 'note'))
        el['type'] = 'error'
        el.addContent('bla')
        n = Note.fromElement(el)

        self.assertEquals(n.note_type, 'error')
        self.assertEquals(n.content, 'bla')
开发者ID:wyn,项目名称:collab,代码行数:10,代码来源:commandTests.py

示例4: test_toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_toElement(self):
        n = Note('bla', 'error')

        el = Element((None, 'note'))
        el['type'] = 'error'
        el.addContent('bla')

        self.assertEquals(n.toElement().toXml(), el.toXml())
开发者ID:wyn,项目名称:collab,代码行数:10,代码来源:commandTests.py

示例5: test_onError_toPublishOnly

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_onError_toPublishOnly(self):
        errors = ['errornode1', 'errornode2']
        node = nodes.PSErrorNode(testJid, self.mockPSClient)
        node.errorChannels = Mock(side_effect=utils.good_side_effect(errors))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onError(el)

        def cb(msg):
            self.assertEquals(self.mockPSClient.publish.call_count, 2)
            self.assertEquals(el.toXml.call_count, 0)

        d.addCallback(cb)
        return d 
开发者ID:wyn,项目名称:collab,代码行数:18,代码来源:nodesTests.py

示例6: test_onOutput_toLog

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_onOutput_toLog(self):
        outputs = ['log']
        node = nodes.PSOutputNode(testJid, self.mockPSClient)
        node.outputChannels = Mock(side_effect=utils.good_side_effect(outputs))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onOutput(el)

        def cb(msg):
            self.assertFalse(self.mockPSClient.publish.called)
            self.assertEquals(el.toXml.call_count, 1)

        d.addCallback(cb)
        return d
开发者ID:wyn,项目名称:collab,代码行数:18,代码来源:nodesTests.py

示例7: test_onError_toPublishErrored

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
    def test_onError_toPublishErrored(self):
        self.mockPSClient.publish = Mock(side_effect=utils.bad_side_effect(error.StanzaError('DISAPPOINTED')))
        errors = ['errornode1', 'errornode2', 'log']
        node = nodes.PSErrorNode(testJid, self.mockPSClient)
        node.errorChannels = Mock(side_effect=utils.good_side_effect(errors))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onError(el)

        def cb(msg):
            self.assertEquals(self.mockPSClient.publish.call_count, 2)
            self.assertEquals(el.toXml.call_count, 1)

        d.addCallback(cb)
        return self.assertFailure(d, error.StanzaError)
开发者ID:wyn,项目名称:collab,代码行数:19,代码来源:nodesTests.py

示例8: Feed

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
class Feed(Element):
    def __init__(self, name, type, uri, tags = None):
        Element.__init__(self, (None, 'feed'), attribs={'type':type})
        self._feedName = Element((None, 'name'))
        self._feedName.addContent(name)
        self.addChild(self._feedName)
       
        self._feedUri = Element((None, 'feedUri'))
        self._feedUri.addContent(uri)
        self.addChild(self._feedUri)

        self._tags = []
        if tags is not None:
            for t in tags:
                tag = Tag(t)
                self.addChild(tag)
                self._tags.append(tag)
              
    def addTag(self, tag):
        eTag = Tag(tag)
        self._tags.append(eTag)
        self.addChild(eTag)        
开发者ID:adamvr,项目名称:MQTT-to-XMPP-Gateway,代码行数:24,代码来源:DeviceDescriptor.py

示例9: Device

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
class Device(Element):
    '''
    classdocs
    '''
    
    def __init__(self, deviceName, rootUri, feeds = None, tags = None):
        Element.__init__(self, (None, 'device'))
        self._deviceName = Element((None, 'name'))
        self._deviceName.addContent(deviceName)
        self.addChild(self._deviceName)
        
        self._rootUri = Element((None, 'rootUri'))
        self._rootUri.addContent(rootUri)
        self.addChild(self._rootUri)
        
        self._feeds = []
        if feeds is not None:
            for f in feeds:
                self._feeds.append(f)
                self.addChild(f)
        
        self._tags = []
        if tags is not None:
            for t in tags:
                tag = Tag(t)
                self.addChild(tag)
                self._tags.append(tag)
                
        
    def addFeed(self, feed):
        self._feeds.append(feed)
        self.addChild(feed)

    def addTag(self, tag):
        eTag = Tag(tag)
        self._tags.append(eTag)
        self.addChild(eTag)        
开发者ID:adamvr,项目名称:MQTT-to-XMPP-Gateway,代码行数:39,代码来源:DeviceDescriptor.py

示例10: XPathTest

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
class XPathTest(unittest.TestCase):
    def setUp(self):
        # Build element:
        # <foo xmlns='testns' attrib1='value1' attrib3="[email protected]/resource">
        #     somecontent
        #     <bar>
        #        <foo>
        #         <gar>DEF</gar>
        #        </foo>
        #     </bar>
        #     somemorecontent
        #     <bar attrib2="value2">
        #        <bar>
        #          <foo/>
        #          <gar>ABC</gar>
        #        </bar>
        #     <bar/>
        #     <bar attrib4='value4' attrib5='value5'>
        #        <foo/>
        #        <gar>JKL</gar>
        #     </bar>
        #     <bar attrib4='value4' attrib5='value4'>
        #        <foo/>
        #        <gar>MNO</gar>
        #     </bar>
        #     <bar attrib4='value4' attrib5='value6'/>
        # </foo>
        self.e = Element(("testns", "foo"))
        self.e["attrib1"] = "value1"
        self.e["attrib3"] = "[email protected]/resource"
        self.e.addContent("somecontent")
        self.bar1 = self.e.addElement("bar")
        self.subfoo = self.bar1.addElement("foo")
        self.gar1 = self.subfoo.addElement("gar")
        self.gar1.addContent("DEF")
        self.e.addContent("somemorecontent")
        self.bar2 = self.e.addElement("bar")
        self.bar2["attrib2"] = "value2"
        self.bar3 = self.bar2.addElement("bar")
        self.subfoo2 = self.bar3.addElement("foo")
        self.gar2 = self.bar3.addElement("gar")
        self.gar2.addContent("ABC")
        self.bar4 = self.e.addElement("bar")
        self.bar5 = self.e.addElement("bar")
        self.bar5["attrib4"] = "value4"
        self.bar5["attrib5"] = "value5"
        self.subfoo3 = self.bar5.addElement("foo")
        self.gar3 = self.bar5.addElement("gar")
        self.gar3.addContent("JKL")
        self.bar6 = self.e.addElement("bar")
        self.bar6["attrib4"] = "value4"
        self.bar6["attrib5"] = "value4"
        self.subfoo4 = self.bar6.addElement("foo")
        self.gar4 = self.bar6.addElement("gar")
        self.gar4.addContent("MNO")
        self.bar7 = self.e.addElement("bar")
        self.bar7["attrib4"] = "value4"
        self.bar7["attrib5"] = "value6"

    def test_staticMethods(self):
        """
        Test basic operation of the static methods.
        """
        self.assertEqual(xpath.matches("/foo/bar", self.e),
                          True)
        self.assertEqual(xpath.queryForNodes("/foo/bar", self.e),
                          [self.bar1, self.bar2, self.bar4,
                           self.bar5, self.bar6, self.bar7])
        self.assertEqual(xpath.queryForString("/foo", self.e),
                          "somecontent")
        self.assertEqual(xpath.queryForStringList("/foo", self.e),
                          ["somecontent", "somemorecontent"])

    def test_locationFooBar(self):
        """
        Test matching foo with child bar.
        """
        xp = XPathQuery("/foo/bar")
        self.assertEqual(xp.matches(self.e), 1)

    def test_locationFooBarFoo(self):
        """
        Test finding foos at the second level.
        """
        xp = XPathQuery("/foo/bar/foo")
        self.assertEqual(xp.matches(self.e), 1)
        self.assertEqual(xp.queryForNodes(self.e), [self.subfoo,
                                                     self.subfoo3,
                                                     self.subfoo4])

    def test_locationNoBar3(self):
        """
        Test not finding bar3.
        """
        xp = XPathQuery("/foo/bar3")
        self.assertEqual(xp.matches(self.e), 0)

    def test_locationAllChilds(self):
        """
        Test finding childs of foo.
#.........这里部分代码省略.........
开发者ID:0004c,项目名称:VTK,代码行数:103,代码来源:test_xpath.py

示例11: XPathTests

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
class XPathTests(unittest.TestCase):
    def setUp(self):
        # Build element:
        # <foo xmlns='testns' attrib1='value1' attrib3="[email protected]/resource">
        #     somecontent
        #     <bar>
        #        <foo>
        #         <gar>DEF</gar>
        #        </foo>
        #     </bar>
        #     somemorecontent
        #     <bar attrib2="value2">
        #        <bar>
        #          <foo/>
        #          <gar>ABC</gar>
        #        </bar>
        #     <bar/>
        #     <bar attrib4='value4' attrib5='value5'>
        #        <foo/>
        #        <gar>JKL</gar>
        #     </bar>
        #     <bar attrib4='value4' attrib5='value4'>
        #        <foo/>
        #        <gar>MNO</gar>
        #     </bar>
        #     <bar attrib4='value4' attrib5='value6' attrib6='á'>
        #         <quux>☃</quux>
        #     </bar>
        # </foo>
        self.e = Element(("testns", "foo"))
        self.e["attrib1"] = "value1"
        self.e["attrib3"] = "[email protected]/resource"
        self.e.addContent(u"somecontent")
        self.bar1 = self.e.addElement("bar")
        self.subfoo = self.bar1.addElement("foo")
        self.gar1 = self.subfoo.addElement("gar")
        self.gar1.addContent(u"DEF")
        self.e.addContent(u"somemorecontent")
        self.bar2 = self.e.addElement("bar")
        self.bar2["attrib2"] = "value2"
        self.bar3 = self.bar2.addElement("bar")
        self.subfoo2 = self.bar3.addElement("foo")
        self.gar2 = self.bar3.addElement("gar")
        self.gar2.addContent(u"ABC")
        self.bar4 = self.e.addElement("bar")
        self.bar5 = self.e.addElement("bar")
        self.bar5["attrib4"] = "value4"
        self.bar5["attrib5"] = "value5"
        self.subfoo3 = self.bar5.addElement("foo")
        self.gar3 = self.bar5.addElement("gar")
        self.gar3.addContent(u"JKL")
        self.bar6 = self.e.addElement("bar")
        self.bar6["attrib4"] = "value4"
        self.bar6["attrib5"] = "value4"
        self.subfoo4 = self.bar6.addElement("foo")
        self.gar4 = self.bar6.addElement("gar")
        self.gar4.addContent(u"MNO")
        self.bar7 = self.e.addElement("bar")
        self.bar7["attrib4"] = "value4"
        self.bar7["attrib5"] = "value6"
        self.bar7["attrib6"] = u"á"
        self.quux = self.bar7.addElement("quux")
        self.quux.addContent(u"\N{SNOWMAN}")

    def test_staticMethods(self):
        """
        Test basic operation of the static methods.
        """
        self.assertEqual(xpath.matches("/foo/bar", self.e),
                          True)
        self.assertEqual(xpath.queryForNodes("/foo/bar", self.e),
                          [self.bar1, self.bar2, self.bar4,
                           self.bar5, self.bar6, self.bar7])
        self.assertEqual(xpath.queryForString("/foo", self.e),
                          "somecontent")
        self.assertEqual(xpath.queryForStringList("/foo", self.e),
                          ["somecontent", "somemorecontent"])

    def test_locationFooBar(self):
        """
        Test matching foo with child bar.
        """
        xp = XPathQuery("/foo/bar")
        self.assertEqual(xp.matches(self.e), 1)

    def test_locationFooBarFoo(self):
        """
        Test finding foos at the second level.
        """
        xp = XPathQuery("/foo/bar/foo")
        self.assertEqual(xp.matches(self.e), 1)
        self.assertEqual(xp.queryForNodes(self.e), [self.subfoo,
                                                     self.subfoo3,
                                                     self.subfoo4])

    def test_locationNoBar3(self):
        """
        Test not finding bar3.
        """
        xp = XPathQuery("/foo/bar3")
#.........这里部分代码省略.........
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:103,代码来源:test_xpath.py

示例12: XPathTest

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
class XPathTest(unittest.TestCase):
    def setUp(self):
        # Build element:
        # <foo xmlns='testns' attrib1='value1' attrib3="[email protected]/resource">
        #     somecontent
        #     <bar>
        #        <foo>
        #         <gar>DEF</gar>
        #        </foo>
        #     </bar>
        #     somemorecontent
        #     <bar attrib2="value2">
        #        <bar>
        #          <foo/>
        #          <gar>ABC</gar>
        #        </bar>
        #     <bar/>
        # </foo>
        self.e = Element(("testns", "foo"))
        self.e["attrib1"] = "value1"
        self.e["attrib3"] = "[email protected]/resource"
        self.e.addContent("somecontent")
        self.bar1 = self.e.addElement("bar")
        self.subfoo = self.bar1.addElement("foo")
        self.gar1 = self.subfoo.addElement("gar")
        self.gar1.addContent("DEF")
        self.e.addContent("somemorecontent")
        self.bar2 = self.e.addElement("bar")
        self.bar2["attrib2"] = "value2"
        self.bar3 = self.bar2.addElement("bar")
        self.subfoo2 = self.bar3.addElement("foo")
        self.gar2 = self.bar3.addElement("gar")
        self.gar2.addContent("ABC")
        self.bar4 = self.e.addElement("bar")

    
    def testStaticMethods(self):
        self.assertEquals(xpath.matches("/foo/bar", self.e),
                          True)
        self.assertEquals(xpath.queryForNodes("/foo/bar", self.e),
                          [self.bar1, self.bar2, self.bar4])
        self.assertEquals(xpath.queryForString("/foo", self.e),
                          "somecontent")
        self.assertEquals(xpath.queryForStringList("/foo", self.e),
                          ["somecontent", "somemorecontent"])
        
    def testFunctionality(self):
        xp = XPathQuery("/foo/bar")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo/bar/foo")
        self.assertEquals(xp.matches(self.e), 1)
        self.assertEquals(xp.queryForNodes(self.e), [self.subfoo])
        
        xp = XPathQuery("/foo/bar3")
        self.assertEquals(xp.matches(self.e), 0)

        xp = XPathQuery("/foo/*")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])

        xp = XPathQuery("/foo[@attrib1]")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("/foo/*[@attrib2='value2']")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.bar2])

# XXX: Revist this, given new grammar
#        xp = XPathQuery("/foo/bar[2]")
#        self.assertEquals(xp.matches(self.e), 1)
#        self.assertEquals(xp.queryForNodes(self.e), [self.bar1])

        xp = XPathQuery("/foo[@xmlns='testns']/bar")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo[@xmlns='badns']/bar2")
        self.assertEquals(xp.matches(self.e), 0)

        xp = XPathQuery("/foo[@attrib1='value1']")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo")
        self.assertEquals(xp.queryForString(self.e), "somecontent")
        self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])

        xp = XPathQuery("/foo/bar")
        self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])

        xp = XPathQuery("/foo[text() = 'somecontent']")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("/foo[not(@nosuchattrib)]")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("//gar")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.gar1, self.gar2])
        self.assertEquals(xp.queryForStringList(self.e), ["DEF", "ABC"])

#.........这里部分代码省略.........
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:103,代码来源:test_xpath.py

示例13: toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addContent [as 别名]
 def toElement(self):
     el = Element((None, 'note'))
     el['type'] = self.note_type
     el.addContent(self.content)
     return el
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:command.py


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