core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
This commit is contained in:
parent
e8ae4435a3
commit
bbadfda25b
2 changed files with 43 additions and 12 deletions
|
|
@ -689,11 +689,13 @@ class SAT(service.Service):
|
|||
hasServerFeature = lambda entity: entity if self.memory.hasServerFeature(feature, entity, profile) else None
|
||||
|
||||
def haveItemsFeature(dummy=None):
|
||||
if jid_ in self.memory.server_identities[profile]:
|
||||
for entity in self.memory.server_identities[profile][jid_].values():
|
||||
if hasServerFeature(entity):
|
||||
return entity
|
||||
return None
|
||||
entities = self.memory.getAllServerIdentities(jid_, profile)
|
||||
if entities is None:
|
||||
return None # no cached data for this server
|
||||
for entity in entities:
|
||||
if hasServerFeature(entity):
|
||||
return entity
|
||||
return None # data are cached but no entity was found
|
||||
|
||||
entity = hasServerFeature(jid_) or haveItemsFeature()
|
||||
if entity:
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ class Memory(object):
|
|||
"""Add a feature discovered from server
|
||||
@param feature: string of the feature
|
||||
@param jid_: the jid of the target server
|
||||
@param profile: which profile is asking this server ?"""
|
||||
@param profile: which profile asked this server?"""
|
||||
if profile not in self.server_features:
|
||||
self.server_features[profile] = {}
|
||||
features = self.server_features[profile].setdefault(jid_, [])
|
||||
|
|
@ -770,7 +770,7 @@ class Memory(object):
|
|||
"""Add an identity discovered from server
|
||||
@param feature: string of the feature
|
||||
@param jid_: the jid of the target server
|
||||
@param profile: which profile is asking this server ?"""
|
||||
@param profile: which profile asked this server?"""
|
||||
if not profile in self.server_identities:
|
||||
self.server_identities[profile] = {}
|
||||
identities = self.server_identities[profile].setdefault(jid_, {})
|
||||
|
|
@ -779,7 +779,13 @@ class Memory(object):
|
|||
identities[(category, type_)].add(entity)
|
||||
|
||||
def getServerServiceEntities(self, category, type_, jid_=None, profile=None):
|
||||
"""Return all available entities for a service"""
|
||||
"""Return all available entities of a server for the service (category, type_)
|
||||
@param category: identity's category
|
||||
@param type_: identitiy's type
|
||||
@param jid_: the jid of the target server (None for profile's server)
|
||||
@param profile: which profile is asking this server?
|
||||
@return: a set of entities or None if no cached data were found
|
||||
"""
|
||||
if jid_ is None:
|
||||
jid_ = self.host.getClientHostJid(profile)
|
||||
if profile in self.server_identities and jid_ in self.server_identities[profile]:
|
||||
|
|
@ -788,9 +794,13 @@ class Memory(object):
|
|||
return None
|
||||
|
||||
def getServerServiceEntity(self, category, type_, jid_=None, profile=None):
|
||||
"""Helper method to get first available entity for a service"""
|
||||
if jid_ is None:
|
||||
jid_ = self.host.getClientHostJid(profile)
|
||||
"""Helper method to get first available entity of a server for the service (category, type_)
|
||||
@param category: identity's category
|
||||
@param type_: identitiy's type
|
||||
@param jid_: the jid of the target server (None for profile's server)
|
||||
@param profile: which profile is asking this server?
|
||||
@return: the first found entity or None if no cached data were found
|
||||
"""
|
||||
entities = self.getServerServiceEntities(category, type_, jid_, profile)
|
||||
if entities is None:
|
||||
warning(_("Entities (%(category)s/%(type)s) of %(server)s not available, maybe they haven't been asked yet?")
|
||||
|
|
@ -799,8 +809,27 @@ class Memory(object):
|
|||
else:
|
||||
return list(entities)[0] if entities else None
|
||||
|
||||
def getAllServerIdentities(self, jid_, profile):
|
||||
"""Helper method to get all identities of a server
|
||||
@param jid_: the jid of the target server (None for profile's server)
|
||||
@param profile: which profile is asking this server?
|
||||
@return: a set of entities or None if no cached data were found
|
||||
"""
|
||||
if jid_ is None:
|
||||
jid_ = self.host.getClientHostJid(profile)
|
||||
if jid_ not in self.server_identities[profile]:
|
||||
return None
|
||||
entities = set()
|
||||
for set_ in self.server_identities[profile][jid_].values():
|
||||
entities.update(set_)
|
||||
return entities
|
||||
|
||||
def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"):
|
||||
"""Tell if the server of the profile has the required feature"""
|
||||
"""Tell if the specified server has the required feature
|
||||
@param feature: requested feature
|
||||
@param jid_: the jid of the target server (None for profile's server)
|
||||
@param profile: which profile is asking this server?
|
||||
"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Trying find server feature for a non-existant profile'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue