diff src/memory/disco.py @ 1552:e0bde0d0b321

core (disco): use of “profile” instead of “profile_key” in several disco methods
author Goffi <goffi@goffi.org>
date Mon, 02 Nov 2015 22:02:41 +0100
parents 1285c714a6cc
children fd143578fe89
line wrap: on
line diff
--- a/src/memory/disco.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/memory/disco.py	Mon Nov 02 22:02:41 2015 +0100
@@ -64,57 +64,57 @@
         # TODO: save hashes in databse, remove legacy hashes
 
     @defer.inlineCallbacks
-    def hasFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def hasFeature(self, feature, jid_=None, profile=C.PROF_KEY_NONE):
         """Tell if an entity has the required feature
 
         @param feature: feature namespace
         @param jid_: jid of the target, or None for profile's server
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         @return: a Deferred which fire a boolean (True if feature is available)
         """
-        disco_infos = yield self.getInfos(jid_, profile_key)
+        disco_infos = yield self.getInfos(jid_, profile)
         defer.returnValue(feature in disco_infos.features)
 
     @defer.inlineCallbacks
-    def checkFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def checkFeature(self, feature, jid_=None, profile=C.PROF_KEY_NONE):
         """Like hasFeature, but raise an exception is feature is not Found
 
         @param feature: feature namespace
         @param jid_: jid of the target, or None for profile's server
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
 
         @raise: exceptions.FeatureNotFound
         """
-        disco_infos = yield self.getInfos(jid_, profile_key)
+        disco_infos = yield self.getInfos(jid_, profile)
         if not feature in disco_infos.features:
             raise failure.Failure(exceptions.FeatureNotFound)
 
     @defer.inlineCallbacks
-    def checkFeatures(self, features, jid_=None, identity=None, profile_key=C.PROF_KEY_NONE):
+    def checkFeatures(self, features, jid_=None, identity=None, profile=C.PROF_KEY_NONE):
         """Like checkFeature, but check several features at once, and check also identity
 
         @param features(iterable[unicode]): features to check
         @param jid_(jid.JID): jid of the target, or None for profile's server
         @param identity(None, tuple(unicode, unicode): if not None, the entity must have an identity with this (category, type) tuple
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
 
         @raise: exceptions.FeatureNotFound
         """
-        disco_infos = yield self.getInfos(jid_, profile_key)
+        disco_infos = yield self.getInfos(jid_, profile)
         if not set(features).issubset(disco_infos.features):
             raise failure.Failure(exceptions.FeatureNotFound())
 
         if identity is not None and identity not in disco_infos.identities:
             raise failure.Failure(exceptions.FeatureNotFound())
 
-    def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def getInfos(self, jid_=None, profile=C.PROF_KEY_NONE):
         """get disco infos from jid_, filling capability hash if needed
 
         @param jid_: jid of the target, or None for profile's server
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         @return: a Deferred which fire disco.DiscoInfo
         """
-        client = self.host.getClient(profile_key)
+        client = self.host.getClient(profile)
         if jid_ is None:
             jid_ = jid.JID(client.jid.host)
         try:
@@ -134,15 +134,15 @@
             return defer.succeed(disco_infos)
 
     @defer.inlineCallbacks
-    def getItems(self, jid_=None, nodeIdentifier='', profile_key=C.PROF_KEY_NONE):
+    def getItems(self, jid_=None, nodeIdentifier='', profile=C.PROF_KEY_NONE):
         """get disco items from jid_, cache them for our own server
 
         @param jid_ (jid.JID): jid of the target, or None for profile's server
         @param nodeIdentifier (str): optional node identifier
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         @return: a Deferred which fire disco.DiscoItems
         """
-        client = self.host.getClient(profile_key)
+        client = self.host.getClient(profile)
         if jid_ is None:
             jid_ = jid.JID(client.jid.host)
             # we cache items only for our own server
@@ -164,13 +164,13 @@
         log.warning(_(u"Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(),
                                                                     'error': failure_.getErrorMessage()})
 
-    def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def findServiceEntities(self, category, type_, jid_=None, profile=C.PROF_KEY_NONE):
         """Return all available items of an entity which correspond to (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_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         @return: a set of found entities
         @raise CancelError: the request timed out
         """
@@ -183,27 +183,27 @@
         def gotItems(items):
             defers_list = []
             for item in items:
-                info_d = self.getInfos(item.entity, profile_key)
+                info_d = self.getInfos(item.entity, profile)
                 info_d.addCallbacks(infosCb, self._infosEb, [item.entity], None, [item.entity])
                 defers_list.append(info_d)
             return defer.DeferredList(defers_list)
 
-        d = self.getItems(jid_, profile_key=profile_key)
+        d = self.getItems(jid_, profile=profile)
         d.addCallback(gotItems)
         d.addCallback(lambda dummy: found_entities)
         reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
         return d
 
-    def findFeaturesSet(self, features, identity=None, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def findFeaturesSet(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
         """Return entities (including jid_ and its items) offering features
 
         @param features: iterable of features which must be present
         @param identity(None, tuple(unicode, unicode)): if not None, accept only this (category/type) identity
         @param jid_: the jid of the target server (None for profile's server)
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         @return: a set of found entities
         """
-        client = self.host.getClient(profile_key)
+        client = self.host.getClient(profile)
         if jid_ is None:
             jid_ = jid.JID(client.jid.host)
         features = set(features)
@@ -218,12 +218,12 @@
         def gotItems(items):
             defer_list = []
             for entity in [jid_] + [item.entity for item in items]:
-                infos_d = self.getInfos(entity, profile_key)
+                infos_d = self.getInfos(entity, profile)
                 infos_d.addCallbacks(infosCb, self._infosEb, [entity], None, [entity])
                 defer_list.append(infos_d)
             return defer.DeferredList(defer_list)
 
-        d = self.getItems(jid_, profile_key=profile_key)
+        d = self.getItems(jid_, profile=profile)
         d.addCallback(gotItems)
         d.addCallback(lambda dummy: found_entities)
         reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
@@ -259,9 +259,11 @@
         """ Discovery method for the bridge
         @param entity_jid_s: entity we want to discover
 
-        @return: list of tu"""
+        @return: list of tuples
+        """
+        profile = self.host.memory.getProfileName(profile_key)
         entity = jid.JID(entity_jid_s)
-        disco_infos = yield self.getInfos(entity, profile_key)
+        disco_infos = yield self.getInfos(entity, profile)
         extensions = {}
         for form_type, form in disco_infos.extensions.items():
             fields = []
@@ -286,7 +288,8 @@
         """ Discovery method for the bridge
         @param entity_jid_s: entity we want to discover
 
-        @return: list of tu"""
+        @return: list of tuples"""
+        profile = self.host.memory.getProfileName(profile_key)
         entity = jid.JID(entity_jid_s)
-        disco_items = yield self.getItems(entity, profile_key=profile_key)
+        disco_items = yield self.getItems(entity, profile=profile)
         defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items])