From f0aec1614f09612b51654082dbd3a5bd67cdecd7 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 14 Feb 2021 11:53:51 +0100 Subject: [PATCH] XEP-0095: API changes - ``accept`` and ``decline`` are now coroutines. --- slixmpp/plugins/xep_0095/stream_initiation.py | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/slixmpp/plugins/xep_0095/stream_initiation.py b/slixmpp/plugins/xep_0095/stream_initiation.py index c7a86780..fd82711a 100644 --- a/slixmpp/plugins/xep_0095/stream_initiation.py +++ b/slixmpp/plugins/xep_0095/stream_initiation.py @@ -81,7 +81,7 @@ class XEP_0095(BasePlugin): self._methods_order.remove((order, method, plugin_name)) self._methods_order.sort() - def _handle_request(self, iq): + async def _handle_request(self, iq): profile = iq['si']['profile'] sid = iq['si']['id'] @@ -119,7 +119,7 @@ class XEP_0095(BasePlugin): receiver = iq['to'] sender = iq['from'] - self.api['add_pending'](receiver, sid, sender, { + await self.api['add_pending'](receiver, sid, sender, { 'response_id': iq['id'], 'method': selected_method, 'profile': profile @@ -153,8 +153,13 @@ class XEP_0095(BasePlugin): options=methods) return si.send(**iqargs) - def accept(self, jid, sid, payload=None, ifrom=None, stream_handler=None): - stream = self.api['get_pending'](ifrom, sid, jid) + async def accept(self, jid, sid, payload=None, ifrom=None, stream_handler=None): + """Accept a stream initiation. + + .. versionchanged:: 1.8.0 + This function is now a coroutine. + """ + stream = await self.api['get_pending'](ifrom, sid, jid) iq = self.xmpp.Iq() iq['id'] = stream['response_id'] iq['to'] = jid @@ -174,16 +179,21 @@ class XEP_0095(BasePlugin): method_plugin = self._methods[stream['method']][0] self.xmpp[method_plugin].api['preauthorize_sid'](ifrom, sid, jid) - self.api['del_pending'](ifrom, sid, jid) + await self.api['del_pending'](ifrom, sid, jid) if stream_handler: self.xmpp.add_event_handler('stream:%s:%s' % (sid, jid), stream_handler, disposable=True) - return iq.send() + return await iq.send() - def decline(self, jid, sid, ifrom=None): - stream = self.api['get_pending'](ifrom, sid, jid) + async def decline(self, jid, sid, ifrom=None): + """Decline a stream initiation. + + .. versionchanged:: 1.8.0 + This function is now a coroutine. + """ + stream = await self.api['get_pending'](ifrom, sid, jid) if not stream: return iq = self.xmpp.Iq() @@ -193,8 +203,8 @@ class XEP_0095(BasePlugin): iq['type'] = 'error' iq['error']['condition'] = 'forbidden' iq['error']['text'] = 'Offer declined' - self.api['del_pending'](ifrom, sid, jid) - return iq.send() + await self.api['del_pending'](ifrom, sid, jid) + return await iq.send() def _add_pending(self, jid, node, ifrom, data): with self._pending_lock: