refactor: remove the now obsolete future_wrapper and asyncio-related module

This commit is contained in:
mathieui 2021-04-04 16:18:24 +02:00
parent ef06429941
commit 9f01d368c0
12 changed files with 18 additions and 45 deletions

View File

@ -19,7 +19,6 @@ from slixmpp.xmlstream.stanzabase import ET, ElementBase, register_stanza_plugin
from slixmpp.xmlstream.handler import * from slixmpp.xmlstream.handler import *
from slixmpp.xmlstream import XMLStream from slixmpp.xmlstream import XMLStream
from slixmpp.xmlstream.matcher import * from slixmpp.xmlstream.matcher import *
from slixmpp.xmlstream.asyncio import asyncio, future_wrapper
from slixmpp.basexmpp import BaseXMPP from slixmpp.basexmpp import BaseXMPP
from slixmpp.clientxmpp import ClientXMPP from slixmpp.clientxmpp import ClientXMPP
from slixmpp.componentxmpp import ComponentXMPP from slixmpp.componentxmpp import ComponentXMPP

View File

@ -11,11 +11,11 @@ from typing import (
Optional Optional
) )
from slixmpp.plugins import BasePlugin, register_plugin from slixmpp.plugins import BasePlugin
from slixmpp import future_wrapper, JID from slixmpp import JID
from slixmpp.stanza import Iq from slixmpp.stanza import Iq
from slixmpp.exceptions import XMPPError 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.handler import CoroutineCallback
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.plugins.xep_0012 import stanza, LastActivity from slixmpp.plugins.xep_0012 import stanza, LastActivity

View File

@ -4,7 +4,6 @@
# This file is part of Slixmpp. # This file is part of Slixmpp.
# See the file LICENSE for copying permission. # See the file LICENSE for copying permission.
import logging import logging
from asyncio import Future
from typing import Optional from typing import Optional
from slixmpp import JID from slixmpp import JID
@ -15,7 +14,6 @@ from slixmpp.xmlstream.handler import CoroutineCallback
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.plugins import BasePlugin from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0054 import VCardTemp, stanza from slixmpp.plugins.xep_0054 import VCardTemp, stanza
from slixmpp import future_wrapper
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -1,4 +1,3 @@
# Slixmpp: The Slick XMPP Library # Slixmpp: The Slick XMPP Library
# Copyright (C) 2015 Emmanuel Gil Peyrot # Copyright (C) 2015 Emmanuel Gil Peyrot
# This file is part of Slixmpp. # This file is part of Slixmpp.
@ -7,11 +6,10 @@ import asyncio
import logging import logging
from uuid import uuid4 from uuid import uuid4
from slixmpp.plugins import BasePlugin, register_plugin from slixmpp.plugins import BasePlugin
from slixmpp import future_wrapper, Iq, Message from slixmpp import Iq, Message
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
from slixmpp.jid import JID 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.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.plugins.xep_0070 import stanza, Confirm from slixmpp.plugins.xep_0070 import stanza, Confirm
@ -52,7 +50,6 @@ class XEP_0070(BasePlugin):
def session_bind(self, jid): def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/http-auth') 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): def ask_confirm(self, jid, id, url, method, *, ifrom=None, message=None):
jid = JID(jid) jid = JID(jid)
if jid.resource: if jid.resource:
@ -70,7 +67,9 @@ class XEP_0070(BasePlugin):
if message is not None: if message is not None:
stanza['body'] = message.format(id=id, url=url, method=method) stanza['body'] = message.format(id=id, url=url, method=method)
stanza.send() stanza.send()
return stanza fut = asyncio.Future()
fut.set_result(stanza)
return fut
else: else:
return stanza.send() return stanza.send()

View File

@ -17,7 +17,6 @@ from slixmpp.exceptions import XMPPError, IqTimeout, IqError
from slixmpp.xmlstream import register_stanza_plugin, ElementBase from slixmpp.xmlstream import register_stanza_plugin, ElementBase
from slixmpp.plugins.base import BasePlugin from slixmpp.plugins.base import BasePlugin
from slixmpp.plugins.xep_0153 import stanza, VCardTempUpdate from slixmpp.plugins.xep_0153 import stanza, VCardTempUpdate
from slixmpp import future_wrapper
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -3,10 +3,11 @@
# Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout # Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
# This file is part of Slixmpp. # This file is part of Slixmpp.
# See the file LICENSE for copying permission. # See the file LICENSE for copying permission.
import asyncio
import logging import logging
from typing import Optional, Callable from typing import Optional, Callable
from slixmpp import asyncio, JID from slixmpp import JID
from slixmpp.xmlstream import register_stanza_plugin, ElementBase from slixmpp.xmlstream import register_stanza_plugin, ElementBase
from slixmpp.plugins.base import BasePlugin, register_plugin from slixmpp.plugins.base import BasePlugin, register_plugin
from slixmpp.plugins.xep_0004.stanza import Form from slixmpp.plugins.xep_0004.stanza import Form

View File

@ -3,6 +3,7 @@
# Copyright (C) 2010 Nathanael C. Fritz # Copyright (C) 2010 Nathanael C. Fritz
# This file is part of Slixmpp. # This file is part of Slixmpp.
# See the file LICENSE for copying permission. # See the file LICENSE for copying permission.
import asyncio
import time import time
import logging import logging
@ -11,7 +12,6 @@ from typing import Optional, Callable, List
from slixmpp.jid import JID from slixmpp.jid import JID
from slixmpp.stanza import Iq from slixmpp.stanza import Iq
from slixmpp import asyncio
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath

View File

@ -9,14 +9,13 @@ import hashlib
from asyncio import Future from asyncio import Future
from typing import Optional from typing import Optional
from slixmpp import future_wrapper, JID from slixmpp import JID
from slixmpp.stanza import Iq, Message, Presence from slixmpp.stanza import Iq, Message, Presence
from slixmpp.exceptions import XMPPError
from slixmpp.xmlstream.handler import CoroutineCallback from slixmpp.xmlstream.handler import CoroutineCallback
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins.base import BasePlugin 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__) log = logging.getLogger(__name__)

View File

@ -5,10 +5,10 @@
# Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se # Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se
# This file is part of Slixmpp. # This file is part of Slixmpp.
# See the file LICENSE for copying permission. # See the file LICENSE for copying permission.
import asyncio
import logging import logging
import time import time
from slixmpp import asyncio
from functools import partial from functools import partial
from slixmpp.xmlstream import JID from slixmpp.xmlstream import JID
from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.handler import Callback

View File

@ -3,10 +3,10 @@
# Copyright (C) 2010 Nathanael C. Fritz # Copyright (C) 2010 Nathanael C. Fritz
# This file is part of Slixmpp. # This file is part of Slixmpp.
# See the file LICENSE for copying permission. # See the file LICENSE for copying permission.
import asyncio
from slixmpp.stanza.rootstanza import RootStanza from slixmpp.stanza.rootstanza import RootStanza
from slixmpp.xmlstream import StanzaBase, ET from slixmpp.xmlstream import StanzaBase, ET
from slixmpp.xmlstream.handler import Waiter, Callback, CoroutineCallback from slixmpp.xmlstream.handler import Callback, CoroutineCallback
from slixmpp.xmlstream.asyncio import asyncio
from slixmpp.xmlstream.matcher import MatchIDSender, MatcherId from slixmpp.xmlstream.matcher import MatchIDSender, MatcherId
from slixmpp.exceptions import IqTimeout, IqError from slixmpp.exceptions import IqTimeout, IqError

View File

@ -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

View File

@ -27,11 +27,11 @@ import ssl
import weakref import weakref
import uuid import uuid
import asyncio
from asyncio import iscoroutinefunction, wait, Future from asyncio import iscoroutinefunction, wait, Future
from contextlib import contextmanager from contextlib import contextmanager
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from slixmpp.xmlstream.asyncio import asyncio
from slixmpp.xmlstream import tostring from slixmpp.xmlstream import tostring
from slixmpp.xmlstream.stanzabase import StanzaBase, ElementBase from slixmpp.xmlstream.stanzabase import StanzaBase, ElementBase
from slixmpp.xmlstream.resolver import resolve, default_resolver from slixmpp.xmlstream.resolver import resolve, default_resolver