# HG changeset patch # User souliane # Date 1387200926 -3600 # Node ID 5aff0beddb28cf0f7f4c389ad79fc23dfe4bf031 # Parent 539f278bc265355dff4eb014695c7b561aa247c7 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py diff -r 539f278bc265 -r 5aff0beddb28 src/core/sat_main.py --- a/src/core/sat_main.py Thu Nov 28 19:23:59 2013 +0100 +++ b/src/core/sat_main.py Mon Dec 16 14:35:26 2013 +0100 @@ -689,11 +689,13 @@ 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: diff -r 539f278bc265 -r 5aff0beddb28 src/memory/memory.py --- a/src/memory/memory.py Thu Nov 28 19:23:59 2013 +0100 +++ b/src/memory/memory.py Mon Dec 16 14:35:26 2013 +0100 @@ -760,7 +760,7 @@ """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 @@ """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 @@ 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 @@ 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 @@ 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'))