core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
This commit is contained in:
parent
2319ce59fb
commit
9895ceb32f
2 changed files with 25 additions and 16 deletions
|
|
@ -703,6 +703,9 @@ class SAT(service.Service):
|
||||||
def checkFeature(self, *args, **kwargs):
|
def checkFeature(self, *args, **kwargs):
|
||||||
return self.memory.disco.checkFeature(*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):
|
def getDiscoInfos(self, *args, **kwargs):
|
||||||
return self.memory.disco.getInfos(*args, **kwargs)
|
return self.memory.disco.getInfos(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,14 +81,30 @@ class Discovery(object):
|
||||||
@param feature: feature namespace
|
@param feature: feature namespace
|
||||||
@param jid_: jid of the target, or None for profile's server
|
@param jid_: jid of the target, or None for profile's server
|
||||||
@param profile_key: %(doc_profile_key)s
|
@param profile_key: %(doc_profile_key)s
|
||||||
@return: None if feature is found
|
|
||||||
|
|
||||||
@raise: exceptions.FeatureNotFound
|
@raise: exceptions.FeatureNotFound
|
||||||
"""
|
"""
|
||||||
disco_infos = yield self.getInfos(jid_, profile_key)
|
disco_infos = yield self.getInfos(jid_, profile_key)
|
||||||
if not feature in disco_infos.features:
|
if not feature in disco_infos.features:
|
||||||
raise exceptions.FeatureNotFound
|
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):
|
def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE):
|
||||||
"""get disco infos from jid_, filling capability hash if needed
|
"""get disco infos from jid_, filling capability hash if needed
|
||||||
|
|
@ -177,12 +193,11 @@ class Discovery(object):
|
||||||
reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
|
reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
|
||||||
return d
|
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
|
"""Return entities (including jid_ and its items) offering features
|
||||||
|
|
||||||
@param features: iterable of features which must be present
|
@param features: iterable of features which must be present
|
||||||
@param category: if not None, accept only this category
|
@param identity(None, tuple(unicode, unicode)): if not None, accept only this (category/type) identity
|
||||||
@param type_: if not None, accept only this type
|
|
||||||
@param jid_: the jid of the target server (None for profile's server)
|
@param jid_: the jid of the target server (None for profile's server)
|
||||||
@param profile_key: %(doc_profile_key)s
|
@param profile_key: %(doc_profile_key)s
|
||||||
@return: a set of found entities
|
@return: a set of found entities
|
||||||
|
|
@ -194,17 +209,8 @@ class Discovery(object):
|
||||||
found_entities = set()
|
found_entities = set()
|
||||||
|
|
||||||
def infosCb(infos, entity):
|
def infosCb(infos, entity):
|
||||||
if category is not None or type_ is not None:
|
if identity is not None and identity not in infos.identities:
|
||||||
categories = set()
|
return
|
||||||
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 features.issubset(infos.features):
|
if features.issubset(infos.features):
|
||||||
found_entities.add(entity)
|
found_entities.add(entity)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue