diff src/memory/memory.py @ 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 03744d9ebc13
children 1def5b7edf9f
line wrap: on
line diff
--- 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'))