core (disco): added checkFeature method + fixed hasFeature test
This commit is contained in:
parent
d454d9a66e
commit
c0105db63c
1 changed files with 20 additions and 0 deletions
|
|
@ -18,6 +18,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 @@ class Discovery(object):
|
|||
@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
|
||||
|
|
|
|||
Loading…
Reference in a new issue