Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0166.py @ 3040:fee60f17ebac
jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\
This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).
During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Sep 2019 08:56:41 +0200 |
parents | ab2696e34d29 |
children | 9d0df638c8b4 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0166.py Wed Sep 25 08:53:38 2019 +0200 +++ b/sat/plugins/plugin_xep_0166.py Wed Sep 25 08:56:41 2019 +0200 @@ -113,9 +113,11 @@ try: del client.jingle_sessions[sid] except KeyError: - log.debug("Jingle session id [{}] is unknown, nothing to delete".format(sid)) + log.debug( + f"Jingle session id {sid!r} is unknown, nothing to delete " + f"[{client.profile}]") else: - log.debug("Jingle session id [{}] deleted".format(sid)) + log.debug(f"Jingle session id {sid!r} deleted [{client.profile}]") ## helpers methods to build stanzas ## @@ -146,7 +148,7 @@ condition=error_condition ) ) - client.send(iq_elt) + return client.send(iq_elt) def _terminateEb(self, failure_): log.warning(_("Error while terminating session: {msg}").format(msg=failure_)) @@ -188,23 +190,22 @@ ) self._delSession(client, sid) - def _jingleErrorCb(self, fail, sid, request, client): + def _jingleErrorCb(self, failure_, session, request, client): """Called when something is going wrong while parsing jingle request The error condition depend of the exceptions raised: exceptions.DataError raise a bad-request condition @param fail(failure.Failure): the exceptions raised - @param sid(unicode): jingle session id + @param session(dict): data of the session @param request(domsih.Element): jingle request @param client: %(doc_client)s """ - log.warning("Error while processing jingle request") - if isinstance(fail, exceptions.DataError): - self.sendError(client, "bad-request", sid, request) + log.warning(f"Error while processing jingle request [{client.profile}]") + if isinstance(failure_, exceptions.DataError): + return self.sendError(client, "bad-request", session['id'], request) else: - log.error("Unmanaged jingle exception") - self._delSession(client, sid) - raise fail + log.error(f"Unmanaged jingle exception: {failure_}") + return self.terminate(client, self.REASON_FAILED_APPLICATION, session) ## methods used by other plugins ## @@ -706,19 +707,10 @@ """ return elt - def _callPlugins( - self, - client, - action, - session, - app_method_name="jingleHandler", - transp_method_name="jingleHandler", - app_default_cb=None, - transp_default_cb=None, - delete=True, - elements=True, - force_element=None, - ): + def _callPlugins(self, client, action, session, app_method_name="jingleHandler", + transp_method_name="jingleHandler", app_default_cb=None, + transp_default_cb=None, delete=True, elements=True, + force_element=None): """Call application and transport plugin methods for all contents @param action(unicode): jingle action name @@ -819,7 +811,7 @@ confirm_dlist = defer.gatherResults(confirm_defers) confirm_dlist.addCallback(self._confirmationCb, session, jingle_elt, client) - confirm_dlist.addErrback(self._jingleErrorCb, session["id"], request, client) + confirm_dlist.addErrback(self._jingleErrorCb, session, request, client) def _confirmationCb(self, confirm_results, session, jingle_elt, client): """Method called when confirmation from user has been received @@ -952,7 +944,7 @@ negociate_defers = [] negociate_defers = self._callPlugins(client, XEP_0166.A_SESSION_ACCEPT, session) - negociate_dlist = defer.DeferredList(negociate_defers) + negociate_dlist = defer.gatherResults(negociate_defers) # after negociations we start the transfer negociate_dlist.addCallback(