comparison src/memory/disco.py @ 1493:1285c714a6cc

core (disco): use of failure.Failure when raising FeatureNotFound to avoid a jump in debugger in debug mode
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2015 16:52:18 +0200
parents 704ca56f5ca9
children e0bde0d0b321
comparison
equal deleted inserted replaced
1492:6ec2741b7268 1493:1285c714a6cc
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
25 from twisted.words.protocols.jabber.error import StanzaError 25 from twisted.words.protocols.jabber.error import StanzaError
26 from twisted.internet import defer 26 from twisted.internet import defer
27 from twisted.internet import reactor 27 from twisted.internet import reactor
28 from twisted.python import failure
28 from sat.core.constants import Const as C 29 from sat.core.constants import Const as C
29 from wokkel import disco 30 from wokkel import disco
30 from base64 import b64encode 31 from base64 import b64encode
31 from hashlib import sha1 32 from hashlib import sha1
32 33
84 85
85 @raise: exceptions.FeatureNotFound 86 @raise: exceptions.FeatureNotFound
86 """ 87 """
87 disco_infos = yield self.getInfos(jid_, profile_key) 88 disco_infos = yield self.getInfos(jid_, profile_key)
88 if not feature in disco_infos.features: 89 if not feature in disco_infos.features:
89 raise exceptions.FeatureNotFound 90 raise failure.Failure(exceptions.FeatureNotFound)
90 91
91 @defer.inlineCallbacks 92 @defer.inlineCallbacks
92 def checkFeatures(self, features, jid_=None, identity=None, profile_key=C.PROF_KEY_NONE): 93 def checkFeatures(self, features, jid_=None, identity=None, profile_key=C.PROF_KEY_NONE):
93 """Like checkFeature, but check several features at once, and check also identity 94 """Like checkFeature, but check several features at once, and check also identity
94 95
99 100
100 @raise: exceptions.FeatureNotFound 101 @raise: exceptions.FeatureNotFound
101 """ 102 """
102 disco_infos = yield self.getInfos(jid_, profile_key) 103 disco_infos = yield self.getInfos(jid_, profile_key)
103 if not set(features).issubset(disco_infos.features): 104 if not set(features).issubset(disco_infos.features):
104 raise exceptions.FeatureNotFound 105 raise failure.Failure(exceptions.FeatureNotFound())
105 106
106 if identity is not None and identity not in disco_infos.identities: 107 if identity is not None and identity not in disco_infos.identities:
107 raise exceptions.FeatureNotFound 108 raise failure.Failure(exceptions.FeatureNotFound())
108 109
109 def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE): 110 def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE):
110 """get disco infos from jid_, filling capability hash if needed 111 """get disco infos from jid_, filling capability hash if needed
111 112
112 @param jid_: jid of the target, or None for profile's server 113 @param jid_: jid of the target, or None for profile's server
156 items = yield client.disco.requestItems(jid_, nodeIdentifier) 157 items = yield client.disco.requestItems(jid_, nodeIdentifier)
157 158
158 defer.returnValue(items) 159 defer.returnValue(items)
159 160
160 161
161 def _infosEb(self, failure, entity_jid): 162 def _infosEb(self, failure_, entity_jid):
162 failure.trap(StanzaError) 163 failure_.trap(StanzaError)
163 log.warning(_(u"Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(), 164 log.warning(_(u"Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(),
164 'error': failure.getErrorMessage()}) 165 'error': failure_.getErrorMessage()})
165 166
166 def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE): 167 def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE):
167 """Return all available items of an entity which correspond to (category, type_) 168 """Return all available items of an entity which correspond to (category, type_)
168 169
169 @param category: identity's category 170 @param category: identity's category