changeset 3224:0404b306641d

core (xmpp): use async corouting for startConnection
author Goffi <goffi@goffi.org>
date Sun, 22 Mar 2020 14:31:48 +0100 (2020-03-22)
parents 163014f09bf4
children 843a9279fb5a
files sat/core/xmpp.py
diffstat 1 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/xmpp.py	Sun Mar 22 14:04:16 2020 +0100
+++ b/sat/core/xmpp.py	Sun Mar 22 14:31:48 2020 +0100
@@ -150,8 +150,7 @@
         return
 
     @classmethod
-    @defer.inlineCallbacks
-    def startConnection(cls, host, profile, max_retries):
+    async def startConnection(cls, host, profile, max_retries):
         """instantiate the entity and start the connection"""
         # FIXME: reconnection doesn't seems to be handled correclty
         #        (client is deleted then recreated from scratch)
@@ -174,11 +173,11 @@
                 None
             )  # will use default value 5222 or be retrieved from a DNS SRV record
 
-        password = yield host.memory.asyncGetParamA(
+        password = await host.memory.asyncGetParamA(
             "Password", "Connection", profile_key=profile
         )
 
-        entity_jid_s = yield host.memory.asyncGetParamA(
+        entity_jid_s = await host.memory.asyncGetParamA(
             "JabberID", "Connection", profile_key=profile)
         entity_jid = jid.JID(entity_jid_s)
 
@@ -187,13 +186,13 @@
             # server returned one, as it will then stay stable in case of reconnection.
             # we only do that for client and if there is a user part, to let server
             # decide for anonymous login
-            resource_dict = yield host.memory.storage.getPrivates(
+            resource_dict = await host.memory.storage.getPrivates(
                 "core:xmpp", ["resource"] , profile=profile)
             try:
                 resource = resource_dict["resource"]
             except KeyError:
                 resource = f"{C.APP_NAME_FILE}.{shortuuid.uuid()}"
-                yield host.memory.storage.setPrivateValue(
+                await host.memory.storage.setPrivateValue(
                     "core:xmpp", "resource", resource, profile=profile)
 
             log.info(_("We'll use the stable resource {resource}").format(
@@ -223,13 +222,13 @@
 
         log.debug(_("setting plugins parents"))
 
-        plugin_conn_cb = yield entity._callConnectionTriggers()
+        plugin_conn_cb = await entity._callConnectionTriggers()
 
         entity.startService()
 
-        yield entity.conn_deferred
+        await entity.conn_deferred
 
-        yield defer.maybeDeferred(entity.entityConnected)
+        await defer.maybeDeferred(entity.entityConnected)
 
         # Call profileConnected callback for all plugins,
         # and print error message if any of them fails
@@ -252,7 +251,7 @@
                             }
                         )
 
-        yield list_d.addCallback(
+        await list_d.addCallback(
             logPluginResults
         )  # FIXME: we should have a timeout here, and a way to know if a plugin freeze
         # TODO: mesure launch time of each plugin
@@ -811,10 +810,9 @@
         self.presence.setHandlerParent(self)
 
     @classmethod
-    @defer.inlineCallbacks
-    def startConnection(cls, host, profile, max_retries):
+    async def startConnection(cls, host, profile, max_retries):
         try:
-            yield super(SatXMPPClient, cls).startConnection(host, profile, max_retries)
+            await super(SatXMPPClient, cls).startConnection(host, profile, max_retries)
         except exceptions.CancelError as e:
             log.warning(f"startConnection cancelled: {e}")
             return