From 9f01d368c008f8775a991ddf8226a15735bc8303 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 4 Apr 2021 16:18:24 +0200 Subject: [PATCH] refactor: remove the now obsolete future_wrapper and asyncio-related module --- slixmpp/__init__.py | 1 - slixmpp/plugins/xep_0012/last_activity.py | 6 +++--- slixmpp/plugins/xep_0054/vcard_temp.py | 2 -- slixmpp/plugins/xep_0070/confirm.py | 13 ++++++------- slixmpp/plugins/xep_0153/vcard_avatar.py | 1 - slixmpp/plugins/xep_0163.py | 3 ++- slixmpp/plugins/xep_0199/ping.py | 2 +- slixmpp/plugins/xep_0231/bob.py | 5 ++--- slixmpp/plugins/xep_0325/control.py | 2 +- slixmpp/stanza/iq.py | 4 ++-- slixmpp/xmlstream/asyncio.py | 22 ---------------------- slixmpp/xmlstream/xmlstream.py | 2 +- 12 files changed, 18 insertions(+), 45 deletions(-) delete mode 100644 slixmpp/xmlstream/asyncio.py diff --git a/slixmpp/__init__.py b/slixmpp/__init__.py index 769a9e31..403c9299 100644 --- a/slixmpp/__init__.py +++ b/slixmpp/__init__.py @@ -19,7 +19,6 @@ from slixmpp.xmlstream.stanzabase import ET, ElementBase, register_stanza_plugin from slixmpp.xmlstream.handler import * from slixmpp.xmlstream import XMLStream from slixmpp.xmlstream.matcher import * -from slixmpp.xmlstream.asyncio import asyncio, future_wrapper from slixmpp.basexmpp import BaseXMPP from slixmpp.clientxmpp import ClientXMPP from slixmpp.componentxmpp import ComponentXMPP diff --git a/slixmpp/plugins/xep_0012/last_activity.py b/slixmpp/plugins/xep_0012/last_activity.py index 61531431..56905de0 100644 --- a/slixmpp/plugins/xep_0012/last_activity.py +++ b/slixmpp/plugins/xep_0012/last_activity.py @@ -11,11 +11,11 @@ from typing import ( Optional ) -from slixmpp.plugins import BasePlugin, register_plugin -from slixmpp import future_wrapper, JID +from slixmpp.plugins import BasePlugin +from slixmpp import JID from slixmpp.stanza import Iq from slixmpp.exceptions import XMPPError -from slixmpp.xmlstream import JID, register_stanza_plugin +from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.handler import CoroutineCallback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins.xep_0012 import stanza, LastActivity diff --git a/slixmpp/plugins/xep_0054/vcard_temp.py b/slixmpp/plugins/xep_0054/vcard_temp.py index 460013b8..c909f6cd 100644 --- a/slixmpp/plugins/xep_0054/vcard_temp.py +++ b/slixmpp/plugins/xep_0054/vcard_temp.py @@ -4,7 +4,6 @@ # This file is part of Slixmpp. # See the file LICENSE for copying permission. import logging -from asyncio import Future from typing import Optional from slixmpp import JID @@ -15,7 +14,6 @@ from slixmpp.xmlstream.handler import CoroutineCallback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins import BasePlugin from slixmpp.plugins.xep_0054 import VCardTemp, stanza -from slixmpp import future_wrapper log = logging.getLogger(__name__) diff --git a/slixmpp/plugins/xep_0070/confirm.py b/slixmpp/plugins/xep_0070/confirm.py index 334f78d4..1edde8d9 100644 --- a/slixmpp/plugins/xep_0070/confirm.py +++ b/slixmpp/plugins/xep_0070/confirm.py @@ -1,4 +1,3 @@ - # Slixmpp: The Slick XMPP Library # Copyright (C) 2015 Emmanuel Gil Peyrot # This file is part of Slixmpp. @@ -7,11 +6,10 @@ import asyncio import logging from uuid import uuid4 -from slixmpp.plugins import BasePlugin, register_plugin -from slixmpp import future_wrapper, Iq, Message -from slixmpp.exceptions import XMPPError, IqError, IqTimeout +from slixmpp.plugins import BasePlugin +from slixmpp import Iq, Message from slixmpp.jid import JID -from slixmpp.xmlstream import JID, register_stanza_plugin +from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins.xep_0070 import stanza, Confirm @@ -52,7 +50,6 @@ class XEP_0070(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/http-auth') - @future_wrapper def ask_confirm(self, jid, id, url, method, *, ifrom=None, message=None): jid = JID(jid) if jid.resource: @@ -70,7 +67,9 @@ class XEP_0070(BasePlugin): if message is not None: stanza['body'] = message.format(id=id, url=url, method=method) stanza.send() - return stanza + fut = asyncio.Future() + fut.set_result(stanza) + return fut else: return stanza.send() diff --git a/slixmpp/plugins/xep_0153/vcard_avatar.py b/slixmpp/plugins/xep_0153/vcard_avatar.py index e2d98b0a..23709c25 100644 --- a/slixmpp/plugins/xep_0153/vcard_avatar.py +++ b/slixmpp/plugins/xep_0153/vcard_avatar.py @@ -17,7 +17,6 @@ from slixmpp.exceptions import XMPPError, IqTimeout, IqError from slixmpp.xmlstream import register_stanza_plugin, ElementBase from slixmpp.plugins.base import BasePlugin from slixmpp.plugins.xep_0153 import stanza, VCardTempUpdate -from slixmpp import future_wrapper log = logging.getLogger(__name__) diff --git a/slixmpp/plugins/xep_0163.py b/slixmpp/plugins/xep_0163.py index d8ab8c8e..46ca4235 100644 --- a/slixmpp/plugins/xep_0163.py +++ b/slixmpp/plugins/xep_0163.py @@ -3,10 +3,11 @@ # Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout # This file is part of Slixmpp. # See the file LICENSE for copying permission. +import asyncio import logging from typing import Optional, Callable -from slixmpp import asyncio, JID +from slixmpp import JID from slixmpp.xmlstream import register_stanza_plugin, ElementBase from slixmpp.plugins.base import BasePlugin, register_plugin from slixmpp.plugins.xep_0004.stanza import Form diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index 89303ad9..03d272dd 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -3,6 +3,7 @@ # Copyright (C) 2010 Nathanael C. Fritz # This file is part of Slixmpp. # See the file LICENSE for copying permission. +import asyncio import time import logging @@ -11,7 +12,6 @@ from typing import Optional, Callable, List from slixmpp.jid import JID from slixmpp.stanza import Iq -from slixmpp import asyncio from slixmpp.exceptions import IqError, IqTimeout from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.matcher import StanzaPath diff --git a/slixmpp/plugins/xep_0231/bob.py b/slixmpp/plugins/xep_0231/bob.py index 30722208..5614b5b0 100644 --- a/slixmpp/plugins/xep_0231/bob.py +++ b/slixmpp/plugins/xep_0231/bob.py @@ -9,14 +9,13 @@ import hashlib from asyncio import Future from typing import Optional -from slixmpp import future_wrapper, JID +from slixmpp import JID from slixmpp.stanza import Iq, Message, Presence -from slixmpp.exceptions import XMPPError from slixmpp.xmlstream.handler import CoroutineCallback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.base import BasePlugin -from slixmpp.plugins.xep_0231 import stanza, BitsOfBinary +from slixmpp.plugins.xep_0231 import BitsOfBinary log = logging.getLogger(__name__) diff --git a/slixmpp/plugins/xep_0325/control.py b/slixmpp/plugins/xep_0325/control.py index 734b3204..467e10d7 100644 --- a/slixmpp/plugins/xep_0325/control.py +++ b/slixmpp/plugins/xep_0325/control.py @@ -5,10 +5,10 @@ # Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se # This file is part of Slixmpp. # See the file LICENSE for copying permission. +import asyncio import logging import time -from slixmpp import asyncio from functools import partial from slixmpp.xmlstream import JID from slixmpp.xmlstream.handler import Callback diff --git a/slixmpp/stanza/iq.py b/slixmpp/stanza/iq.py index 044c9df8..34e56f60 100644 --- a/slixmpp/stanza/iq.py +++ b/slixmpp/stanza/iq.py @@ -3,10 +3,10 @@ # Copyright (C) 2010 Nathanael C. Fritz # This file is part of Slixmpp. # See the file LICENSE for copying permission. +import asyncio from slixmpp.stanza.rootstanza import RootStanza from slixmpp.xmlstream import StanzaBase, ET -from slixmpp.xmlstream.handler import Waiter, Callback, CoroutineCallback -from slixmpp.xmlstream.asyncio import asyncio +from slixmpp.xmlstream.handler import Callback, CoroutineCallback from slixmpp.xmlstream.matcher import MatchIDSender, MatcherId from slixmpp.exceptions import IqTimeout, IqError diff --git a/slixmpp/xmlstream/asyncio.py b/slixmpp/xmlstream/asyncio.py deleted file mode 100644 index b42b366a..00000000 --- a/slixmpp/xmlstream/asyncio.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -asyncio-related utilities -""" - -import asyncio -from functools import wraps - -def future_wrapper(func): - """ - Make sure the result of a function call is an asyncio.Future() - object. - """ - @wraps(func) - def wrapper(*args, **kwargs): - result = func(*args, **kwargs) - if isinstance(result, asyncio.Future): - return result - future = asyncio.Future() - future.set_result(result) - return future - - return wrapper diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 8d90abf8..45d814fd 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -27,11 +27,11 @@ import ssl import weakref import uuid +import asyncio from asyncio import iscoroutinefunction, wait, Future from contextlib import contextmanager import xml.etree.ElementTree as ET -from slixmpp.xmlstream.asyncio import asyncio from slixmpp.xmlstream import tostring from slixmpp.xmlstream.stanzabase import StanzaBase, ElementBase from slixmpp.xmlstream.resolver import resolve, default_resolver