changeset 4066:e75827204fe0

plugin XEP-0092: use `client` instead of `profile_key` in `version_get`
author Goffi <goffi@goffi.org>
date Tue, 30 May 2023 22:23:55 +0200
parents 34c8e7e4fa52
children 3f62c2445df1
files sat/plugins/plugin_xep_0092.py
diffstat 1 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0092.py	Tue May 30 22:23:37 2023 +0200
+++ b/sat/plugins/plugin_xep_0092.py	Tue May 30 22:23:55 2023 +0200
@@ -17,12 +17,16 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from sat.core.i18n import _
-from sat.core.constants import Const as C
-from twisted.internet import reactor, defer
+from typing import Tuple
+
+from twisted.internet import defer, reactor
 from twisted.words.protocols.jabber import jid
 from wokkel import compat
+
 from sat.core import exceptions
+from sat.core.constants import Const as C
+from sat.core.core_types import SatXMPPEntity
+from sat.core.i18n import _
 from sat.core.log import getLogger
 
 log = getLogger(__name__)
@@ -65,22 +69,26 @@
             name, version, os = data
             return (name or "", version or "", os or "")
 
-        d = self.version_get(jid.JID(entity_jid_s), profile_key)
+        client = self.host.get_client(profile_key)
+        d = self.version_get(client, jid.JID(entity_jid_s))
         d.addCallback(prepare_for_bridge)
         return d
 
-    def version_get(self, jid_, profile_key=C.PROF_KEY_NONE):
-        """ Ask version of the client that jid_ is running
+    def version_get(
+        self,
+        client: SatXMPPEntity,
+        jid_: jid.JID,
+    ) -> Tuple[str, str, str]:
+        """Ask version of the client that jid_ is running
+
         @param jid_: jid from who we want to know client's version
-        @param profile_key: %(doc_profile_key)s
-        @return (tuple): a defered which fire a tuple with the following data (None if not available):
-                 - name: Natural language name of the software
-                 - version: specific version of the software
-                 - os: operating system of the queried entity
+        @return: a defered which fire a tuple with the following data (None if not available):
+            - name: Natural language name of the software
+            - version: specific version of the software
+            - os: operating system of the queried entity
         """
-        client = self.host.get_client(profile_key)
 
-        def version_get(__):
+        def do_version_get(__):
             iq_elt = compat.IQ(client.xmlstream, "get")
             iq_elt["to"] = jid_.full()
             iq_elt.addElement("query", NS_VERSION)
@@ -89,7 +97,7 @@
             return d
 
         d = self.host.check_feature(client, NS_VERSION, jid_)
-        d.addCallback(version_get)
+        d.addCallback(do_version_get)
         reactor.callLater(
             TIMEOUT, d.cancel
         )  # XXX: timeout needed because some clients don't answer the IQ
@@ -111,7 +119,7 @@
         return tuple(ret)
 
     def _whois(self, client, whois_msg, mess_data, target_jid):
-        """ Add software/OS information to whois """
+        """Add software/OS information to whois"""
 
         def version_cb(version_data):
             name, version, os = version_data
@@ -129,6 +137,6 @@
             else:
                 whois_msg.append(_("Client software version request timeout"))
 
-        d = self.version_get(target_jid, client.profile)
+        d = self.version_get(client, target_jid)
         d.addCallbacks(version_cb, version_eb)
         return d