# HG changeset patch # User Goffi # Date 1396261393 -7200 # Node ID 027a054c6dda6fe836c68133f6eff8a806bd2a5d # Parent 5e8e8a034411e897c8e4db8b1cb6533f3e648ee6 core (disco): added checkFeature method + fixed hasFeature test diff -r 5e8e8a034411 -r 027a054c6dda src/core/sat_main.py --- a/src/core/sat_main.py Mon Mar 31 12:23:13 2014 +0200 +++ b/src/core/sat_main.py Mon Mar 31 12:23:13 2014 +0200 @@ -611,6 +611,9 @@ def hasFeature(self, *args, **kwargs): return self.memory.disco.hasFeature(*args, **kwargs) + def checkFeature(self, *args, **kwargs): + return self.memory.disco.checkFeature(*args, **kwargs) + def getDiscoInfos(self, *args, **kwargs): return self.memory.disco.getInfos(*args, **kwargs) diff -r 5e8e8a034411 -r 027a054c6dda src/memory/disco.py --- a/src/memory/disco.py Mon Mar 31 12:23:13 2014 +0200 +++ b/src/memory/disco.py Mon Mar 31 12:23:13 2014 +0200 @@ -18,6 +18,7 @@ # along with this program. If not, see . from sat.core.i18n import _ +from sat.core import exceptions from logging import debug, info, warning, error from twisted.words.protocols.jabber import jid from twisted.internet import defer @@ -67,6 +68,22 @@ @return: a Deferred which fire a boolean (True if feature is available) """ disco_info = yield self.getInfos(jid_, profile_key) + defer.returnValue(feature in disco_info.features) + + @defer.inlineCallbacks + def checkFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE): + """Like hasFeature, but raise an exception is feature is not Found + + @param feature: feature namespace + @param jid_: jid of the target, or None for profile's server + @param profile_key: %(doc_profile_key)s + @return: None if feature is found + + @raise: exceptions.FeatureNotFound + """ + disco_info = yield self.getInfos(jid_, profile_key) + if not feature in disco_info.features: + raise exceptions.FeatureNotFound defer.returnValue(feature in disco_info) @defer.inlineCallbacks