changeset 3900:6c93a18b6250

plugin XEP-0050: use coroutine + minor code readability improvments: rel 372
author Goffi <goffi@goffi.org>
date Wed, 21 Sep 2022 22:33:59 +0200
parents 1e64f1ed3ebd
children 43024e50b701
files sat/plugins/plugin_xep_0050.py
diffstat 1 files changed, 10 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0050.py	Wed Sep 21 22:32:36 2022 +0200
+++ b/sat/plugins/plugin_xep_0050.py	Wed Sep 21 22:33:59 2022 +0200
@@ -88,19 +88,11 @@
         self.label = label
         self.node = node
         self.features = [disco.DiscoFeature(feature) for feature in features]
-        (
-            self.allowed_jids,
-            self.allowed_groups,
-            self.allowed_magics,
-            self.forbidden_jids,
-            self.forbidden_groups,
-        ) = (
-            allowed_jids,
-            allowed_groups,
-            allowed_magics,
-            forbidden_jids,
-            forbidden_groups,
-        )
+        self.allowed_jids = allowed_jids
+        self.allowed_groups = allowed_groups
+        self.allowed_magics = allowed_magics
+        self.forbidden_jids = forbidden_jids
+        self.forbidden_groups = forbidden_groups
         self.sessions = Sessions(timeout=timeout)
 
     @property
@@ -624,12 +616,11 @@
     def _run(self, service_jid_s="", node="", profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)
         service_jid = jid.JID(service_jid_s) if service_jid_s else None
-        d = self.run(client, service_jid, node or None)
+        d = defer.ensureDeferred(self.run(client, service_jid, node or None))
         d.addCallback(lambda xmlui: xmlui.toXml())
         return d
 
-    @defer.inlineCallbacks
-    def run(self, client, service_jid=None, node=None):
+    async def run(self, client, service_jid=None, node=None):
         """Run an ad-hoc command
 
         @param service_jid(jid.JID, None): jid of the ad-hoc service
@@ -643,16 +634,16 @@
         session_id, session_data = self.requesting.newSession(profile=client.profile)
         session_data["jid"] = service_jid
         if node is None:
-            xmlui = yield self.listUI(client, service_jid)
+            xmlui = await self.listUI(client, service_jid)
         else:
             session_data["node"] = node
-            cb_data = yield self.requestingEntity(
+            cb_data = await self.requestingEntity(
                 {"session_id": session_id}, client.profile
             )
             xmlui = cb_data["xmlui"]
 
         xmlui.session_id = session_id
-        defer.returnValue(xmlui)
+        return xmlui
 
     def list(self, client, to_jid):
         """Request available commands