# HG changeset patch # User Goffi # Date 1440511501 -7200 # Node ID 704ca56f5ca99c9a00370ef0198ae8eab7918b28 # Parent 55cff13b1f109aee1aa240351f5c990ae294437c core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures diff -r 55cff13b1f10 -r 704ca56f5ca9 src/core/sat_main.py --- a/src/core/sat_main.py Tue Aug 25 15:39:16 2015 +0200 +++ b/src/core/sat_main.py Tue Aug 25 16:05:01 2015 +0200 @@ -703,6 +703,9 @@ def checkFeature(self, *args, **kwargs): return self.memory.disco.checkFeature(*args, **kwargs) + def checkFeatures(self, *args, **kwargs): + return self.memory.disco.checkFeatures(*args, **kwargs) + def getDiscoInfos(self, *args, **kwargs): return self.memory.disco.getInfos(*args, **kwargs) diff -r 55cff13b1f10 -r 704ca56f5ca9 src/memory/disco.py --- a/src/memory/disco.py Tue Aug 25 15:39:16 2015 +0200 +++ b/src/memory/disco.py Tue Aug 25 16:05:01 2015 +0200 @@ -81,14 +81,30 @@ @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_infos = yield self.getInfos(jid_, profile_key) if not feature in disco_infos.features: raise exceptions.FeatureNotFound - defer.returnValue(feature in disco_infos) + + @defer.inlineCallbacks + def checkFeatures(self, features, jid_=None, identity=None, profile_key=C.PROF_KEY_NONE): + """Like checkFeature, but check several features at once, and check also identity + + @param features(iterable[unicode]): features to check + @param jid_(jid.JID): jid of the target, or None for profile's server + @param identity(None, tuple(unicode, unicode): if not None, the entity must have an identity with this (category, type) tuple + @param profile_key: %(doc_profile_key)s + + @raise: exceptions.FeatureNotFound + """ + disco_infos = yield self.getInfos(jid_, profile_key) + if not set(features).issubset(disco_infos.features): + raise exceptions.FeatureNotFound + + if identity is not None and identity not in disco_infos.identities: + raise exceptions.FeatureNotFound def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE): """get disco infos from jid_, filling capability hash if needed @@ -177,12 +193,11 @@ reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout return d - def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=C.PROF_KEY_NONE): + def findFeaturesSet(self, features, identity=None, jid_=None, profile_key=C.PROF_KEY_NONE): """Return entities (including jid_ and its items) offering features @param features: iterable of features which must be present - @param category: if not None, accept only this category - @param type_: if not None, accept only this type + @param identity(None, tuple(unicode, unicode)): if not None, accept only this (category/type) identity @param jid_: the jid of the target server (None for profile's server) @param profile_key: %(doc_profile_key)s @return: a set of found entities @@ -194,17 +209,8 @@ found_entities = set() def infosCb(infos, entity): - if category is not None or type_ is not None: - categories = set() - types = set() - for identity in infos.identities: - id_cat, id_type = identity - categories.add(id_cat) - types.add(id_type) - if category is not None and category not in categories: - return - if type_ is not None and type_ not in types: - return + if identity is not None and identity not in infos.identities: + return if features.issubset(infos.features): found_entities.add(entity)