core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py

This commit is contained in:
souliane 2013-12-16 14:35:26 +01:00
commit bbadfda25b

View file

@ -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'))