changeset 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 591c32dbfb0b
children ebf97c1ac14a
files src/memory/disco.py src/plugins/plugin_misc_groupblog.py src/plugins/plugin_xep_0033.py src/plugins/plugin_xep_0045.py src/plugins/plugin_xep_0055.py src/plugins/plugin_xep_0060.py src/plugins/plugin_xep_0115.py
diffstat 7 files changed, 50 insertions(+), 48 deletions(-) [+]
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])
--- a/src/plugins/plugin_misc_groupblog.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_misc_groupblog.py	Mon Nov 02 22:02:41 2015 +0100
@@ -23,7 +23,7 @@
 log = getLogger(__name__)
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
-from twisted.words.xish.domish import Element, generateElementsNamed
+from twisted.words.xish.domish import generateElementsNamed
 from sat.core import exceptions
 from wokkel import disco, data_form, iwokkel
 from wokkel import rsm
@@ -140,7 +140,7 @@
     def profileConnected(self, profile):
         client = self.host.getClient(profile)
         try:
-            yield self.host.checkFeatures((NS_PUBSUB_GROUPBLOG, NS_PUBSUB_AUTO_CREATE), profile_key=profile)
+            yield self.host.checkFeatures((NS_PUBSUB_GROUPBLOG, NS_PUBSUB_AUTO_CREATE), profile=profile)
         except exceptions.FeatureNotFound:
             client.server_groupblog_available = False
             log.warning(_(u"Server is not able to manage item-access pubsub, we can't use group blog"))
@@ -177,7 +177,7 @@
         if not hasattr(client, "item_access_pubsub"):
             log.debug(_('Looking for item-access powered pubsub server'))
             #we don't have any pubsub server featuring item access yet
-            item_access_pubsubs = yield self.host.findFeaturesSet((NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK), "pubsub", "service", profile_key=profile)
+            item_access_pubsubs = yield self.host.findFeaturesSet((NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK), "pubsub", "service", profile=profile)
             # item_access_pubsubs = yield self.host.findFeaturesSet((NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK), "pubsub", "service", profile_key=profile)
             try:
                 client.item_access_pubsub = item_access_pubsubs.pop()
--- a/src/plugins/plugin_xep_0033.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0033.py	Mon Nov 02 22:02:41 2015 +0100
@@ -99,7 +99,7 @@
                 self.sendAndStoreMessage(mess_data, entries, profile)
                 log.debug("XEP-0033 took over")
                 raise failure.Failure(exceptions.CancelError())
-            d = self.host.findFeaturesSet([NS_ADDRESS], profile_key=profile)
+            d = self.host.findFeaturesSet([NS_ADDRESS], profile=profile)
             d.addCallbacks(discoCallback, lambda dummy: discoCallback(None))
             return d
 
@@ -154,7 +154,7 @@
         defer_list = []
         for type_, jid_ in entries:
             d = defer.Deferred()
-            d.addCallback(self.host.findFeaturesSet, jid_=JID(JID(jid_).host), profile_key=profile)
+            d.addCallback(self.host.findFeaturesSet, jid_=JID(JID(jid_).host), profile=profile)
             d.addCallbacks(discoCallback, errback, callbackArgs=[jid_], errbackArgs=[jid_])
             d.callback([NS_ADDRESS])
             defer_list.append(d)
--- a/src/plugins/plugin_xep_0045.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0045.py	Mon Nov 02 22:02:41 2015 +0100
@@ -100,7 +100,7 @@
         def assign_service(service):
             client = self.host.getClient(profile)
             client.muc_service = service
-        return self.getMUCService(profile_key=profile).addCallback(assign_service)
+        return self.getMUCService(profile=profile).addCallback(assign_service)
 
     def checkClient(self, profile):
         """Check if the profile is connected and has used the MUC feature.
@@ -304,14 +304,14 @@
         return self.clients[profile].rec_subjects.values()
 
     @defer.inlineCallbacks
-    def getMUCService(self, jid_=None, profile_key=C.PROF_KEY_NONE):
+    def getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE):
         """Return first found MUC service of an entity
 
         @param jid_: entity which may have a MUC service, or None for our own server
-        @param profile_key: %(doc_profile_key)s
+        @param profile: %(doc_profile)s
         """
         muc_service = None
-        services = yield self.host.findServiceEntities("conference", "text", jid_, profile_key=profile_key)
+        services = yield self.host.findServiceEntities("conference", "text", jid_, profile=profile)
         for service in services:
             if ".irc." not in service.userhost():
                 # FIXME:
--- a/src/plugins/plugin_xep_0055.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0055.py	Mon Nov 02 22:02:41 2015 +0100
@@ -27,7 +27,6 @@
 from wokkel import data_form
 from sat.core.constants import Const as C
 from sat.core.exceptions import DataError
-from sat.memory.memory import Sessions
 from sat.tools import xml_tools
 
 from wokkel import disco, iwokkel
@@ -84,11 +83,11 @@
 
     def _getHostServices(self, profile):
         """Return the jabber search services associated to the user host.
-        
+
         @param profile (unicode): %(doc_profile)s
         @return: list[jid.JID]
         """
-        d = self.host.findFeaturesSet([NS_SEARCH], profile_key=profile)
+        d = self.host.findFeaturesSet([NS_SEARCH], profile=profile)
         return d.addCallback(lambda set_: list(set_))
 
 
@@ -125,7 +124,7 @@
 
     def _addSimpleSearchUI(self, services, main_ui, data, profile):
         """Add to the main UI a tab for the simple search.
-        
+
         Display a single input field and search on the main service (it actually does one search per search field and then compile the results).
 
         @param services (list[jid.JID]): search services offered by the user server
@@ -143,7 +142,7 @@
         sub_cont = main_ui.main_container.addTab("simple_search", label=_("Simple search"), container=xml_tools.VerticalContainer)
         main_ui.changeContainer(sub_cont.append(xml_tools.PairsContainer(main_ui)))
         xml_tools.dataForm2Widgets(main_ui, form)
-        
+
         # FIXME: add colspan attribute to divider? (we are in a PairsContainer)
         main_ui.addDivider('blank')
         main_ui.addDivider('blank')  # here we added a blank line before the button
@@ -243,7 +242,7 @@
             name = widget.getAttribute("name")
             if adv_data.get(name):
                 widget.setAttribute("value", adv_data[name])
-        
+
         # FIXME: add colspan attribute to divider? (we are in a PairsContainer)
         main_ui.addDivider('blank')
         main_ui.addDivider('blank')  # here we added a blank line before the button
@@ -267,11 +266,11 @@
 
     def _displaySearchResult(self, main_ui, elt):
         """Display the search results.
-        
+
         @param main_ui (XMLUI): the main XMLUI instance
         @param elt (domish.Element):  form result element
         """
-        if [child for child in elt.children if child.name == "item"]: 
+        if [child for child in elt.children if child.name == "item"]:
             headers, xmlui_data = xml_tools.dataFormResult2XMLUIData(elt)
             if "jid" in headers:  # use XMLUI JidsListWidget to display the results
                 values = {}
@@ -458,7 +457,7 @@
         @return: a deferred dict{unicode: unicode}
         """
         d = self._getHostServices(profile)
-        
+
         def got_services(services):
             service_jid = services[0]
             d = self.host.plugins["XEP-0050"].requestCommandsList(service_jid, profile)
--- a/src/plugins/plugin_xep_0060.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0060.py	Mon Nov 02 22:02:41 2015 +0100
@@ -96,7 +96,7 @@
     @defer.inlineCallbacks
     def profileConnected(self, profile):
         client = self.host.getClient(profile)
-        pubsub_services = yield self.host.findServiceEntities("pubsub", "service", profile_key = profile)
+        pubsub_services = yield self.host.findServiceEntities("pubsub", "service", profile=profile)
         if pubsub_services:
             # we use one of the found services as our default pubsub service
             client.pubsub_service = pubsub_services.pop()
--- a/src/plugins/plugin_xep_0115.py	Mon Nov 02 22:02:41 2015 +0100
+++ b/src/plugins/plugin_xep_0115.py	Mon Nov 02 22:02:41 2015 +0100
@@ -66,7 +66,7 @@
         client.caps_optimize = None
 
         if XEP_0115.cap_hash is None:
-            disco_d.addCallback(lambda dummy: self.host.hasFeature(NS_CAPS_OPTIMIZE, profile_key=profile))
+            disco_d.addCallback(lambda dummy: self.host.hasFeature(NS_CAPS_OPTIMIZE, profile=profile))
             def updateOptimize(optimize):
                 client.caps_optimize = optimize
                 if optimize: