本文整理汇总了Python中wokkel.generic.parseXml函数的典型用法代码示例。如果您正苦于以下问题:Python parseXml函数的具体用法?Python parseXml怎么用?Python parseXml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseXml函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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''
示例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)
示例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)
示例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
示例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)
示例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
示例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())