changeset 747:5aff0beddb28

core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
author souliane <souliane@mailoo.org>
date Mon, 16 Dec 2013 14:35:26 +0100
parents 539f278bc265
children a0f4a80a6536
files src/core/sat_main.py src/memory/memory.py
diffstat 2 files changed, 43 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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:
--- 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'))