# HG changeset patch # User Goffi # Date 1584883908 -3600 # Node ID 0404b306641db83b45fb97cddc8991c4a9eb5115 # Parent 163014f09bf45fa139afd3dbdd56c036787dea59 core (xmpp): use async corouting for startConnection diff -r 163014f09bf4 -r 0404b306641d sat/core/xmpp.py --- 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