• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python generic.parseXml函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wokkel.generic.parseXml函数的典型用法代码示例。如果您正苦于以下问题:Python parseXml函数的具体用法?Python parseXml怎么用?Python parseXml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_full_cycle

    def test_full_cycle(self):
        # foo logs in.
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='hamlet'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # bar logs in.
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='hamlet'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # foo changes the Sheakespearean text to plain english,
        # and creates a patch.
        original2plain_patch = self.dmp.patch_make(self.original, self.plain)
        original2plain_text = self.dmp.patch_toText(original2plain_patch)
        xml = "<iq from='[email protected]' to='example.com' type='set'>" + \
              "<patch xmlns='http://jarn.com/ns/collaborative-editing' node='hamlet'>" + \
              original2plain_text + \
              "</patch></iq>"
        self.stub.send(parseXml(xml))

        # Before receiving a patch from the server bar has already updated
        # his own version to trekkie and sends it away.
        original2trekkie_patch = self.dmp.patch_make(self.original, self.trekkie)
        original2trekkie_text = self.dmp.patch_toText(original2trekkie_patch)
        xml = "<iq from='[email protected]' to='example.com' type='set'>" + \
              "<patch xmlns='http://jarn.com/ns/collaborative-editing' node='hamlet'>" + \
              original2trekkie_text + \
              "</patch></iq>"
        self.stub.send(parseXml(xml))

        # So now, both have obtained a patch to apply each other changes on
        # the already changed document. They are the same and merged perfectly.
        iq_to_foo = self.stub.output[-1]
        plain2final_text = iq_to_foo.patch.children[0]
        plain2final_patch = self.dmp.patch_fromText(plain2final_text)
        foo_result = self.dmp.patch_apply(plain2final_patch, self.plain)
        foo_final = foo_result[0]
        self.assertEqual(self.final, foo_final)

        iq_to_bar = self.stub.output[-3]
        trekkie2final_text = iq_to_bar.patch.children[0]
        trekkie2final_patch = self.dmp.patch_fromText(trekkie2final_text)
        bar_result = self.dmp.patch_apply(trekkie2final_patch, self.trekkie)
        bar_final = bar_result[0]
        self.assertEqual(self.final, bar_final)
开发者ID:collective,项目名称:collective.xmpp.collaboration,代码行数:50,代码来源:test_protocol_functional.py


示例2: test_fromElementItems

    def test_fromElementItems(self):
        """
        Test items when creating L{disco.DiscoInfo} from L{domish.Element}.
        """
        xml = """<query xmlns='http://jabber.org/protocol/disco#info'>
                   <identity category='conference'
                             type='text'
                             name='A Dark Cave'/>
                   <feature var='http://jabber.org/protocol/muc'/>
                   <feature var='jabber:iq:register'/>
                   <x xmlns='jabber:x:data' type='result'>
                     <field var='FORM_TYPE' type='hidden'>
                       <value>http://jabber.org/protocol/muc#roominfo</value>
                     </field>
                   </x>
                 </query>"""

        element = parseXml(xml)
        info = disco.DiscoInfo.fromElement(element)

        info = list(info)
        self.assertEqual(4, len(info))

        identity = info[0]
        self.assertEqual(u'conference', identity.category)

        self.assertEqual(u'http://jabber.org/protocol/muc', info[1])
        self.assertEqual(u'jabber:iq:register', info[2])

        extension = info[3]
        self.assertEqual(u'http://jabber.org/protocol/muc#roominfo',
                         extension.formNamespace)
开发者ID:Gandi,项目名称:wokkel,代码行数:32,代码来源:test_disco.py


示例3: test_fromElement

    def test_fromElement(self):
        """
        Test properties when creating L{disco.DiscoInfo} from L{domish.Element}.
        """
        xml = """<query xmlns='http://jabber.org/protocol/disco#info'>
                   <identity category='conference'
                             type='text'
                             name='A Dark Cave'/>
                   <feature var='http://jabber.org/protocol/muc'/>
                   <feature var='jabber:iq:register'/>
                   <x xmlns='jabber:x:data' type='result'>
                     <field var='FORM_TYPE' type='hidden'>
                       <value>http://jabber.org/protocol/muc#roominfo</value>
                     </field>
                   </x>
                 </query>"""

        element = parseXml(xml)
        info = disco.DiscoInfo.fromElement(element)

        self.assertIn(u'http://jabber.org/protocol/muc', info.features)
        self.assertIn(u'jabber:iq:register', info.features)

        self.assertIn((u'conference', u'text'), info.identities)
        self.assertEqual(u'A Dark Cave',
                          info.identities[(u'conference', u'text')])

        self.assertIn(u'http://jabber.org/protocol/muc#roominfo',
                      info.extensions)
开发者ID:Gandi,项目名称:wokkel,代码行数:29,代码来源:test_disco.py


示例4: _translate

        def _translate(tx, recipient, out):
            qlist = ['SELECT `id`, `timestamp`, `content`, `expire_timestamp` FROM stanzas_%s WHERE `recipient` = ?' % (t, )
                     for t in self.tables]
            qargs = [recipient.user for t in self.tables]

            tx.execute('SELECT * FROM (' + ' UNION '.join(qlist) + ') a ORDER BY `timestamp`', qargs)
            data = tx.fetchall()
            for row in data:
                stanzaId = str(row[0])
                d = {
                     'id': stanzaId,
                     'timestamp': datetime.datetime.utcfromtimestamp(row[1] / 1e3),
                     'expire': datetime.datetime.utcfromtimestamp(row[3]) if row[3] else None
                }
                d['stanza'] = generic.parseXml(row[2].decode('utf-8').encode('utf-8'))

                """
                Add a <storage/> element to the stanza; this way components have
                a way to know if stanza is coming from storage.
                """
                stor = d['stanza'].addElement((xmlstream2.NS_XMPP_STORAGE, 'storage'))
                stor['id'] = stanzaId

                out.append(d)
            return out
开发者ID:bekomy,项目名称:xmppserver,代码行数:25,代码来源:storage.py


示例5: _translate

        def _translate(tx, recipient, out):
            qlist = [
                "SELECT `id`, `timestamp`, `content`, `expire_timestamp` FROM stanzas_%s WHERE `recipient` = ?" % (t,)
                for t in self.tables
            ]
            qargs = [recipient.user for t in self.tables]

            tx.execute("SELECT * FROM (" + " UNION ".join(qlist) + ") a ORDER BY `timestamp`", qargs)
            data = tx.fetchall()
            for row in data:
                stanzaId = str(row[0])
                d = {
                    "id": stanzaId,
                    "timestamp": datetime.datetime.utcfromtimestamp(row[1] / 1e3),
                    "expire": datetime.datetime.utcfromtimestamp(row[3]) if row[3] else None,
                }
                d["stanza"] = generic.parseXml(row[2].decode("utf-8").encode("utf-8"))

                """
                Add a <storage/> element to the stanza; this way components have
                a way to know if stanza is coming from storage.
                """
                stor = d["stanza"].addElement((xmlstream2.NS_XMPP_STORAGE, "storage"))
                stor["id"] = stanzaId

                out.append(d)
            return out
开发者ID:huayuxian,项目名称:xmppserver,代码行数:27,代码来源:storage.py


示例6: test_getAffiliations_current

    def test_getAffiliations_current(self, sendMock):
        xml = """
        <iq type='result'
            from='pubsub.shakespeare.lit'
            to='[email protected]/elsinore'
            id='ent1'>
          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
            <affiliations node='princely_musings'>
              <affiliation jid='[email protected]' affiliation='owner'/>
              <affiliation jid='[email protected]' affiliation='outcast'/>
            </affiliations>
          </pubsub>
        </iq>
        """
        el = parseXml(xml)
        sendMock.side_effect = utils.good_side_effect(el)
        xs = Mock()
        d = psaff.getAffiliations(jid.JID('[email protected]/elsinore'), 'princely_musings', xs)

        def cb(affs):
            expected = {
                jid.internJID('[email protected]').userhostJID(): 'owner',
                jid.internJID('[email protected]').userhostJID(): 'outcast',
                }
            self.assertEquals(expected, affs)
            sendMock.assert_called_once_with(xs)

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


示例7: test_getAffiliationsForJid_current

    def test_getAffiliationsForJid_current(self, sendMock):
        xml = """
        <iq type='result'
            from='pubsub.shakespeare.lit'
            to='[email protected]'
            id='affil1'>
          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
            <affiliations>
              <affiliation node='node1' affiliation='owner'/>
              <affiliation node='node2' affiliation='publisher'/>
              <affiliation node='node5' affiliation='outcast'/>
              <affiliation node='node6' affiliation='owner'/>
            </affiliations>
          </pubsub>
        </iq>
        """
        el = parseXml(xml)
        sendMock.side_effect = utils.good_side_effect(el)
        xs = Mock()
        d = psaff.getAffiliationsForJid(jid.JID('[email protected]'), xs)

        def cb(affs):
            expected = {
                'node1': 'owner',
                'node2': 'publisher',
                'node5': 'outcast',
                'node6': 'owner'
                }
            self.assertEquals(expected, affs)
            sendMock.assert_called_once_with(xs)

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


示例8: test_noHeaders

 def test_noHeaders(self):
     """
     A stanza without headers results in an empty dictionary.
     """
     stanza = parseXml("""<message/>""")
     headers = shim.extractHeaders(stanza)
     self.assertEquals({}, headers)
开发者ID:B-Rich,项目名称:wokkel,代码行数:7,代码来源:test_shim.py


示例9: render_POST

    def render_POST(self, request):
        if request.requestHeaders.hasHeader(b'Event'):
            payload = None
        else:
            payload = parseXml(request.content.read())

        self.callback(payload, request.requestHeaders)

        request.setResponseCode(http.NO_CONTENT)
        return b''
开发者ID:ralphm,项目名称:idavoll,代码行数:10,代码来源:gateway.py


示例10: test_fromElementMissingStamp

    def test_fromElementMissingStamp(self):
        """
        A missing timestamp results in C{None} for the stamp attribute.
        """
        xml = parseXml(u"""
            <delay xmlns="urn:xmpp:delay"/>
        """)

        delay = Delay.fromElement(xml)
        self.assertIdentical(None, delay.stamp)
开发者ID:Gandi,项目名称:wokkel,代码行数:10,代码来源:test_delay.py


示例11: test_fromElementNoNode

    def test_fromElementNoNode(self):
        """
        Test creating L{disco.DiscoItems} from L{domish.Element}, no node.
        """
        xml = """<query xmlns='http://jabber.org/protocol/disco#items'/>"""

        element = parseXml(xml)
        items = disco.DiscoItems.fromElement(element)

        self.assertEqual(u'', items.nodeIdentifier)
开发者ID:Gandi,项目名称:wokkel,代码行数:10,代码来源:test_disco.py


示例12: parseResponse

    def parseResponse(self, contents, protocol):
        self.client = protocol

        try:
            element = parseXml(contents)
            body_tag = element
            elements = element.children
        except Exception, ex:
            log.err(str(ex))
            raise
开发者ID:twonds,项目名称:twisted_helper,代码行数:10,代码来源:httpb_client.py


示例13: test_fromElementBadStamp

    def test_fromElementBadStamp(self):
        """
        A malformed timestamp results in C{None} for the stamp attribute.
        """
        xml = parseXml(u"""
            <delay xmlns="urn:xmpp:delay" stamp="foobar"/>
        """)

        delay = Delay.fromElement(xml)
        self.assertIdentical(None, delay.stamp)
开发者ID:Gandi,项目名称:wokkel,代码行数:10,代码来源:test_delay.py


示例14: test_getSubscriptionsForJid_current

    def test_getSubscriptionsForJid_current(self, sendMock):
        xml = """
        <iq type='result'
            from='pubsub.shakespeare.lit'
            to='[email protected]'
            id='subscriptions1'>
          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
            <subscriptions>
              <subscription node='node1' jid='[email protected]' subscription='subscribed'/>
              <subscription node='node2' jid='[email protected]' subscription='subscribed'/>
              <subscription node='node5' jid='[email protected]' subscription='unconfigured'/>
              <subscription node='node6' jid='[email protected]' subscription='subscribed' subid='123-abc'/>
              <subscription node='node6' jid='[email protected]' subscription='subscribed' subid='004-yyy'/>
            </subscriptions>
          </pubsub>
        </iq>
        """
        el = parseXml(xml)
        sendMock.side_effect = utils.good_side_effect(el)
        xs = Mock()
        d = psaff.getSubscriptionsForJid(jid.JID('[email protected]'), xs)

        def cb(subs):
            actual = [a.toElement().toXml() for a in subs]
            expected = [
                ps.Subscription(
                    nodeIdentifier='node1',
                    subscriber=jid.internJID('[email protected]').userhostJID(),
                    state='subscribed'),
                ps.Subscription(
                    nodeIdentifier='node2',
                    subscriber=jid.internJID('[email protected]').userhostJID(),
                    state='subscribed'),
                ps.Subscription(
                    nodeIdentifier='node5',
                    subscriber=jid.internJID('[email protected]').userhostJID(),
                    state='unconfigured'),
                ps.Subscription(
                    nodeIdentifier='node6',
                    subscriber=jid.internJID('[email protected]').userhostJID(),
                    state='subscribed',
                    subscriptionIdentifier='123-abc'),
                ps.Subscription(
                    nodeIdentifier='node6',
                    subscriber=jid.internJID('[email protected]').userhostJID(),
                    state='subscribed',
                    subscriptionIdentifier='004-yyy'),
                ]
            self.assertEquals(len(actual), 5)
            for ex in expected:
                self.assertIn(ex.toElement().toXml(), actual)
            sendMock.assert_called_once_with(xs)

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


示例15: test_getShadowCopyIQ

    def test_getShadowCopyIQ(self):
        # User [email protected] joins
        self.protocol.mock_text['test-node'] = 'foo'
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # And requests the shadow copy of 'test-node'
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                    <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </iq>"""
        self.stub.send(parseXml(xml))
        response = self.stub.output[-1]
        self.assertEqual("<iq to='[email protected]' from='example.com' type='result'>" +
                         "<shadowcopy xmlns='http://jarn.com/ns/collaborative-editing' node='test-node'>foo</shadowcopy>" +
                         "</iq>", response.toXml())

        # Requesting the shadow copy of an non-existent node should result in Unauthorized error
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                    <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing'
                           node='unknown-node'/>
                 </iq>"""
        self.stub.send(parseXml(xml))
        response = self.stub.output[-1]
        self.assertEqual("<iq to='[email protected]' from='example.com' type='error'>" +
                         "<error xmlns='http://jarn.com/ns/collaborative-editing'>Unauthorized</error></iq>",
                         response.toXml())

        # User [email protected] who has not sent a presence to the component should not be able
        # to retrieve the text.
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                 <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </iq>"""
        self.stub.send(parseXml(xml))
        response = self.stub.output[-1]
        self.assertEqual("<iq to='[email protected]' from='example.com' type='error'>" +
                         "<error xmlns='http://jarn.com/ns/collaborative-editing'>Unauthorized</error></iq>",
                         response.toXml())
开发者ID:collective,项目名称:collective.xmpp.collaboration,代码行数:42,代码来源:test_protocol.py


示例16: test_fromElementSender

    def test_fromElementSender(self):
        """
        The optional original sender address is parsed as a JID.
        """
        xml = parseXml(u"""
            <delay xmlns="urn:xmpp:delay" stamp="2002-09-10T23:08:25Z"
                                          from="[email protected]"/>
        """)

        delay = Delay.fromElement(xml)
        self.assertEqual(JID(u'[email protected]'), delay.sender)
开发者ID:Gandi,项目名称:wokkel,代码行数:11,代码来源:test_delay.py


示例17: test_fromElementVersionEmpty

 def test_fromElementVersionEmpty(self):
     """
     The ver attribute may be empty.
     """
     xml = """
         <iq type='get' to='[email protected]/Home' from='[email protected]'>
           <query xmlns='jabber:iq:roster' ver=''/>
         </iq>
     """
     request = xmppim.RosterRequest.fromElement(parseXml(xml))
     self.assertEqual('', request.version)
开发者ID:Gandi,项目名称:wokkel,代码行数:11,代码来源:test_xmppim.py


示例18: test_fromParentElementLegacy

 def test_fromParentElementLegacy(self):
     """
     A child element with legacy delay information is found and parsed.
     """
     xml = parseXml(u"""
         <message>
           <x xmlns="jabber:x:delay" stamp="20020910T23:08:25"/>
         </message>
     """)
     stanza = DelayStanza.fromElement(xml)
     self.assertNotIdentical(None, stanza.delay)
开发者ID:Gandi,项目名称:wokkel,代码行数:11,代码来源:test_delay.py


示例19: test_onPingHandled

    def test_onPingHandled(self):
        """
        The ping handler should mark the stanza as handled.
        """
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                   <ping xmlns='urn:xmpp:ping'/>
                 </iq>"""
        iq = parseXml(xml)
        self.stub.send(iq)

        self.assertTrue(iq.handled)
开发者ID:Gandi,项目名称:wokkel,代码行数:11,代码来源:test_ping.py


示例20: test_fromElementSenderBad

    def test_fromElementSenderBad(self):
        """
        An invalid original sender address results in C{None}.
        """
        xml = parseXml(u"""
            <delay xmlns="urn:xmpp:delay" stamp="2002-09-10T23:08:25Z"
                                          from="[email protected]@example.org"/>
        """)

        delay = Delay.fromElement(xml)
        self.assertIdentical(None, delay.sender)
开发者ID:Gandi,项目名称:wokkel,代码行数:11,代码来源:test_delay.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.XmlStreamStub类代码示例发布时间:2022-05-26
下一篇:
Python client.XMPPClient类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap