comparison src/memory/disco.py @ 951:027a054c6dda

core (disco): added checkFeature method + fixed hasFeature test
author Goffi <goffi@goffi.org>
date Mon, 31 Mar 2014 12:23:13 +0200
parents e1842ebcb2f3
children 0e8c2414f89c
comparison
equal deleted inserted replaced
950:5e8e8a034411 951:027a054c6dda
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core import exceptions
21 from logging import debug, info, warning, error 22 from logging import debug, info, warning, error
22 from twisted.words.protocols.jabber import jid 23 from twisted.words.protocols.jabber import jid
23 from twisted.internet import defer 24 from twisted.internet import defer
24 from sat.core.constants import Const as C 25 from sat.core.constants import Const as C
25 from wokkel import disco 26 from wokkel import disco
65 @param jid_: jid of the target, or None for profile's server 66 @param jid_: jid of the target, or None for profile's server
66 @param profile_key: %(doc_profile_key)s 67 @param profile_key: %(doc_profile_key)s
67 @return: a Deferred which fire a boolean (True if feature is available) 68 @return: a Deferred which fire a boolean (True if feature is available)
68 """ 69 """
69 disco_info = yield self.getInfos(jid_, profile_key) 70 disco_info = yield self.getInfos(jid_, profile_key)
71 defer.returnValue(feature in disco_info.features)
72
73 @defer.inlineCallbacks
74 def checkFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE):
75 """Like hasFeature, but raise an exception is feature is not Found
76
77 @param feature: feature namespace
78 @param jid_: jid of the target, or None for profile's server
79 @param profile_key: %(doc_profile_key)s
80 @return: None if feature is found
81
82 @raise: exceptions.FeatureNotFound
83 """
84 disco_info = yield self.getInfos(jid_, profile_key)
85 if not feature in disco_info.features:
86 raise exceptions.FeatureNotFound
70 defer.returnValue(feature in disco_info) 87 defer.returnValue(feature in disco_info)
71 88
72 @defer.inlineCallbacks 89 @defer.inlineCallbacks
73 def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE): 90 def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE):
74 """get disco infos from jid_, filling capability hash if needed 91 """get disco infos from jid_, filling capability hash if needed