本文整理汇总了Python中twisted.words.protocols.jabber.error.exceptionFromStanza函数的典型用法代码示例。如果您正苦于以下问题:Python exceptionFromStanza函数的具体用法?Python exceptionFromStanza怎么用?Python exceptionFromStanza使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exceptionFromStanza函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testLegacy
def testLegacy(self):
"""
Test legacy operations of exceptionFromStanza.
Given a realistic stanza with only legacy (pre-XMPP) error information,
check if a sane exception is returned.
Using this stanza::
<message type='error'
to='[email protected]/Home'
from='[email protected]'>
<body>Are you there?</body>
<error code='502'>Unable to resolve hostname.</error>
</message>
"""
stanza = domish.Element((None, 'stanza'))
p = stanza.addElement('body', content='Are you there?')
e = stanza.addElement('error', content='Unable to resolve hostname.')
e['code'] = '502'
result = error.exceptionFromStanza(stanza)
self.assert_(isinstance(result, error.StanzaError))
self.assertEquals('service-unavailable', result.condition)
self.assertEquals('wait', result.type)
self.assertEquals('Unable to resolve hostname.', result.text)
self.assertEquals([p], result.children)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:27,代码来源:test_jabbererror.py
示例2: callback
def callback(iq):
if getattr(iq, 'handled', False):
return
try:
d = xs.queryDeferreds[iq["id"]]
except KeyError:
pass
else:
del xs.queryDeferreds[iq["id"]]
iq.handled = True
try :
_ex = xpath.queryForNodes("/message/x", iq, )[0]
except IndexError :
d.errback(error.exceptionFromStanza(iq, ), )
else :
if "type" in _ex.attributes and _ex['type'] == 'error':
d.errback(error.exceptionFromStanza(_ex, ), )
else:
d.callback(iq)
开发者ID:srothan,项目名称:io,代码行数:20,代码来源:xmppim.py
示例3: _onIQResponse
def _onIQResponse(self, iq):
try:
d = self._iqDeferreds[iq["id"]]
except KeyError:
return
del self._iqDeferreds[iq["id"]]
iq.handled = True
if iq['type'] == 'error':
d.errback(error.exceptionFromStanza(iq))
else:
d.callback(iq)
开发者ID:LScarpinati,项目名称:sylkserver,代码行数:12,代码来源:server.py
示例4: callback
def callback(iq):
if getattr(iq, 'handled', False):
return
try:
d = xmlstream.iqDeferreds[iq["id"]]
except KeyError:
pass
else:
del iq["id"]
iq.handled = True
if iq['type'] == 'error':
d.errback(failure.Failure(error.exceptionFromStanza(iq)))
else:
d.callback(iq)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:15,代码来源:xmlstream.py
示例5: test_noHandler
def test_noHandler(self):
"""
Test when the request is not recognised.
"""
iq = domish.Element((None, 'iq'))
iq['type'] = 'set'
iq['id'] = 'r1'
handler = DummyIQHandler()
handler.handleRequest(iq)
response = handler.output[-1]
self.assertEquals(None, response.uri)
self.assertEquals('iq', response.name)
self.assertEquals('error', response['type'])
e = error.exceptionFromStanza(response)
self.assertEquals('feature-not-implemented', e.condition)
开发者ID:thepaul,项目名称:wokkel,代码行数:16,代码来源:test_subprotocols.py
示例6: callback
def callback(iq):
"""
Handle iq response by firing associated deferred.
"""
if getattr(iq, 'handled', False):
return
try:
d = xs.iqDeferreds[iq["id"]]
except KeyError:
pass
else:
del xs.iqDeferreds[iq["id"]]
iq.handled = True
if iq['type'] == 'error':
d.errback(error.exceptionFromStanza(iq))
else:
d.callback(iq)
开发者ID:Almad,项目名称:twisted,代码行数:18,代码来源:xmlstream.py
示例7: test_notImplemented
def test_notImplemented(self):
"""
Test response when the request is recognised but not implemented.
"""
class Handler(DummyIQHandler):
def onGet(self, iq):
raise NotImplementedError()
iq = domish.Element((None, 'iq'))
iq['type'] = 'get'
iq['id'] = 'r1'
handler = Handler()
handler.handleRequest(iq)
response = handler.output[-1]
self.assertEquals(None, response.uri)
self.assertEquals('iq', response.name)
self.assertEquals('error', response['type'])
e = error.exceptionFromStanza(response)
self.assertEquals('feature-not-implemented', e.condition)
开发者ID:thepaul,项目名称:wokkel,代码行数:20,代码来源:test_subprotocols.py
示例8: test_failure
def test_failure(self):
"""
Test response when the request is handled unsuccessfully.
"""
class Handler(DummyIQHandler):
def onGet(self, iq):
raise error.StanzaError('forbidden')
iq = domish.Element((None, 'iq'))
iq['type'] = 'get'
iq['id'] = 'r1'
handler = Handler()
handler.handleRequest(iq)
response = handler.output[-1]
self.assertEquals(None, response.uri)
self.assertEquals('iq', response.name)
self.assertEquals('error', response['type'])
e = error.exceptionFromStanza(response)
self.assertEquals('forbidden', e.condition)
开发者ID:thepaul,项目名称:wokkel,代码行数:20,代码来源:test_subprotocols.py
示例9: testBasic
def testBasic(self):
"""
Test basic operations of exceptionFromStanza.
Given a realistic stanza, check if a sane exception is returned.
Using this stanza::
<iq type='error'
from='pubsub.shakespeare.lit'
to='[email protected]/barracks'
id='subscriptions1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<subscriptions/>
</pubsub>
<error type='cancel'>
<feature-not-implemented
xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
<unsupported xmlns='http://jabber.org/protocol/pubsub#errors'
feature='retrieve-subscriptions'/>
</error>
</iq>
"""
stanza = domish.Element((None, 'stanza'))
p = stanza.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
p.addElement('subscriptions')
e = stanza.addElement('error')
e['type'] = 'cancel'
e.addElement((NS_XMPP_STANZAS, 'feature-not-implemented'))
uc = e.addElement(('http://jabber.org/protocol/pubsub#errors',
'unsupported'))
uc['feature'] = 'retrieve-subscriptions'
result = error.exceptionFromStanza(stanza)
self.assert_(isinstance(result, error.StanzaError))
self.assertEquals('feature-not-implemented', result.condition)
self.assertEquals('cancel', result.type)
self.assertEquals(uc, result.appCondition)
self.assertEquals([p], result.children)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:40,代码来源:test_jabbererror.py
示例10: test_failureUnknown
def test_failureUnknown(self):
"""
Test response when the request handler raises a non-stanza-error.
"""
class TestError(Exception):
pass
class Handler(DummyIQHandler):
def onGet(self, iq):
raise TestError()
iq = domish.Element((None, 'iq'))
iq['type'] = 'get'
iq['id'] = 'r1'
handler = Handler()
handler.handleRequest(iq)
response = handler.output[-1]
self.assertEquals(None, response.uri)
self.assertEquals('iq', response.name)
self.assertEquals('error', response['type'])
e = error.exceptionFromStanza(response)
self.assertEquals('internal-server-error', e.condition)
self.assertEquals(1, len(self.flushLoggedErrors(TestError)))
开发者ID:thepaul,项目名称:wokkel,代码行数:24,代码来源:test_subprotocols.py
示例11: onResponse
def onResponse(element):
if element.getAttribute("type") == "error":
d.errback(error.exceptionFromStanza(element))
else:
d.callback(UserPresence.fromElement(element))
开发者ID:Gandi,项目名称:wokkel,代码行数:5,代码来源:muc.py
注:本文中的twisted.words.protocols.jabber.error.exceptionFromStanza函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论