Replace asyncio.ensure_future() with asyncio.create_task()

The latter function got introduced in Python 3.7, which is conveniently
our MSPV, so let’s use that.
This commit is contained in:
Emmanuel Gil Peyrot 2021-11-18 15:23:46 +01:00 committed by mathieui
parent 2c59fa067a
commit 79bbbdb3e6
15 changed files with 36 additions and 39 deletions

View file

@ -95,4 +95,4 @@ class Plugin(BasePlugin):
else:
self.api.run_command('/help exec')
return
asyncio.ensure_future(self.async_exec(command, arg))
asyncio.create_task(self.async_exec(command, arg))

View file

@ -141,7 +141,7 @@ from poezio import tabs
class Plugin(BasePlugin):
def init(self):
if self.config.get('initial_connect', True):
asyncio.ensure_future(
asyncio.create_task(
self.initial_connect()
)

View file

@ -123,7 +123,7 @@ class Plugin(BasePlugin):
jid = arg
if not arg:
jid = self.api.current_tab().jid
asyncio.ensure_future(
asyncio.create_task(
self.command_ping(jid)
)
@ -140,7 +140,7 @@ class Plugin(BasePlugin):
jid = JID(arg)
except InvalidJID:
return self.api.information('Invalid JID: %s' % arg, 'Error')
asyncio.ensure_future(
asyncio.create_task(
self.command_ping(jid.full)
)
@ -156,7 +156,7 @@ class Plugin(BasePlugin):
res = current.get_highest_priority_resource()
if res is not None:
jid =res.jid
asyncio.ensure_future(
asyncio.create_task(
self.command_ping(jid)
)

View file

@ -78,7 +78,7 @@ class Plugin(BasePlugin):
return
filename, = args
filename = expanduser(filename)
asyncio.ensure_future(self.send_upload(filename))
asyncio.create_task(self.send_upload(filename))
@staticmethod
def completion_filename(the_input):

View file

@ -91,10 +91,7 @@ Configuration
"""
from asyncio import (
ensure_future,
gather,
)
import asyncio
from functools import reduce
from typing import Dict
@ -174,10 +171,10 @@ class Plugin(BasePlugin):
]
for name, handler in handlers:
self.core.xmpp.del_event_handler(name, handler)
ensure_future(self._stop())
asyncio.create_task(self._stop())
async def _stop(self):
await gather(
await asyncio.gather(
self.core.xmpp.plugin['xep_0108'].stop(),
self.core.xmpp.plugin['xep_0107'].stop(),
self.core.xmpp.plugin['xep_0196'].stop(),

View file

@ -266,7 +266,7 @@ class Plugin(BasePlugin):
self.api.information('Invalid JID: %s' % arg, 'Error')
return
asyncio.ensure_future(
asyncio.create_task(
self._get_vcard(jid)
)
@ -290,7 +290,7 @@ class Plugin(BasePlugin):
jid = JID(arg)
except InvalidJID:
return self.api.information('Invalid JID: %s' % arg, 'Error')
asyncio.ensure_future(
asyncio.create_task(
self._get_vcard(jid)
)
@ -301,11 +301,11 @@ class Plugin(BasePlugin):
return
current = self.api.current_tab().selected_row
if isinstance(current, Resource):
asyncio.ensure_future(
asyncio.create_task(
self._get_vcard(JID(current.jid).bare)
)
elif isinstance(current, Contact):
asyncio.ensure_future(
asyncio.create_task(
self._get_vcard(current.bare_jid)
)

View file

@ -298,7 +298,7 @@ class CommandCore:
jid = self.core.tabs.current_tab.jid
if jid is None or not jid.domain:
return None
asyncio.ensure_future(
asyncio.create_task(
self._list_async(jid)
)
@ -453,7 +453,7 @@ class CommandCore:
room, nick = self._parse_join_jid(args[0] if args else '')
password = args[1] if len(args) > 1 else None
asyncio.ensure_future(
asyncio.create_task(
self._add_bookmark(
room=room,
nick=nick,
@ -478,7 +478,7 @@ class CommandCore:
autojoin = (method == 'local' or
(len(args) > 1 and args[1].lower() == 'true'))
asyncio.ensure_future(
asyncio.create_task(
self._add_bookmark(room, nick, autojoin, password, method)
)
@ -596,7 +596,7 @@ class CommandCore:
else:
jid = args[0]
asyncio.ensure_future(
asyncio.create_task(
self._remove_bookmark_routine(jid)
)
@ -983,7 +983,7 @@ class CommandCore:
return self.core.information('Invalid JID for /impromptu: %s' % args[0], 'Error')
jids.add(bare)
asyncio.ensure_future(self.core.impromptu(jids))
asyncio.create_task(self.core.impromptu(jids))
self.core.information('Invited %s to a random room' % (', '.join(jids)), 'Info')
@command_args_parser.quoted(1, 1, [''])
@ -1043,7 +1043,7 @@ class CommandCore:
if jid is None:
self.core.information('No specified JID to block', 'Error')
else:
asyncio.ensure_future(self._block_async(jid))
asyncio.create_task(self._block_async(jid))
async def _block_async(self, jid: JID):
"""Block a JID, asynchronously"""
@ -1096,7 +1096,7 @@ class CommandCore:
jid = JID(current_tab.jid.bare)
if jid is not None:
asyncio.ensure_future(
asyncio.create_task(
self._unblock_async(jid)
)
else:
@ -1185,7 +1185,7 @@ class CommandCore:
self.core.information('Invalid alternative room JID: "%s"' % args[2], 'Error')
return
asyncio.ensure_future(do_destroy(room, reason, altroom))
asyncio.create_task(do_destroy(room, reason, altroom))
@command_args_parser.quoted(1, 1, [''])
def bind(self, args):

View file

@ -444,7 +444,7 @@ class Core:
if value not in ('pep', 'privatexml'):
return
self.bookmarks.preferred = value
asyncio.ensure_future(
asyncio.create_task(
self.bookmarks.save(self.xmpp, core=self)
)

View file

@ -108,7 +108,7 @@ class HandlerCore:
await self.core.check_bookmark_storage(features)
def find_identities(self, _):
asyncio.ensure_future(
asyncio.create_task(
self.core.xmpp['xep_0030'].get_info_from_domain(),
)
@ -1097,7 +1097,7 @@ class HandlerCore:
if config.getbool('enable_user_nick'):
self.core.xmpp.plugin['xep_0172'].publish_nick(
nick=self.core.own_nick, callback=dumb_callback)
asyncio.ensure_future(self.core.xmpp.plugin['xep_0115'].update_caps())
asyncio.create_task(self.core.xmpp.plugin['xep_0115'].update_caps())
# Start the ping's plugin regular event
self.core.xmpp.set_keepalive_values()

View file

@ -24,7 +24,7 @@ def has_identity(xmpp, jid, identity, on_true=None, on_false=None):
if not res and on_false is not None:
on_false()
asyncio.ensure_future(
asyncio.create_task(
xmpp.plugin['xep_0030'].get_info(jid=jid, callback=_cb)
)

View file

@ -321,7 +321,7 @@ class MAMFiller:
self.tab = tab
self.logger = logger
logger.fd_busy(tab.jid)
self.future = asyncio.ensure_future(self.fetch_routine())
self.future = asyncio.create_task(self.fetch_routine())
self.done = asyncio.Event()
self.limit = limit
self.result = 0

View file

@ -109,7 +109,7 @@ def join_groupchat(
xmpp.plugin['xep_0045'].rooms[jid] = {}
xmpp.plugin['xep_0045'].our_nicks[jid] = to.resource
asyncio.ensure_future(
asyncio.create_task(
xmpp.plugin['xep_0030'].get_info(jid=jid, callback=on_disco)
)

View file

@ -351,7 +351,7 @@ class Tab:
if hasattr(self.input, "reset_completion"):
self.input.reset_completion()
if asyncio.iscoroutinefunction(func):
asyncio.ensure_future(func(arg))
asyncio.create_task(func(arg))
else:
func(arg)
return True
@ -979,7 +979,7 @@ class ChatTab(Tab):
def on_scroll_up(self):
if not self.query_status:
from poezio.log_loader import LogLoader
asyncio.ensure_future(
asyncio.create_task(
LogLoader(logger, self, config.getbool('use_log')).scroll_requested()
)
return self.text_win.scroll_up(self.text_win.height - 1)
@ -1036,10 +1036,10 @@ class OneToOneTab(ChatTab):
if mam_filler.result == 0:
self.handle_message(initial)
asyncio.ensure_future(fallback_no_mam())
asyncio.create_task(fallback_no_mam())
elif use_log and initial:
self.handle_message(initial, display=False)
asyncio.ensure_future(
asyncio.create_task(
LogLoader(logger, self, use_log).tab_open()
)

View file

@ -96,7 +96,7 @@ class BookmarksTab(Tab):
if bm in self.bookmarks:
self.bookmarks.remove(bm)
asyncio.ensure_future(
asyncio.create_task(
self.save_routine()
)

View file

@ -154,14 +154,14 @@ class MucTab(ChatTab):
"""
The user do not want to send their config, send an iq cancel
"""
asyncio.ensure_future(self.core.xmpp['xep_0045'].cancel_config(self.jid))
asyncio.create_task(self.core.xmpp['xep_0045'].cancel_config(self.jid))
self.core.close_tab()
def send_config(self, form: Form) -> None:
"""
The user sends their config to the server
"""
asyncio.ensure_future(self.core.xmpp['xep_0045'].set_room_config(self.jid, form))
asyncio.create_task(self.core.xmpp['xep_0045'].set_room_config(self.jid, form))
self.core.close_tab()
def join(self) -> None:
@ -610,7 +610,7 @@ class MucTab(ChatTab):
},
),
)
asyncio.ensure_future(LogLoader(
asyncio.create_task(LogLoader(
logger, self, config.get_by_tabname('use_log', self.general_jid)
).tab_open())
@ -1513,7 +1513,7 @@ class MucTab(ChatTab):
bookmark = self.core.bookmarks[self.jid]
if bookmark:
bookmark.autojoin = False
asyncio.ensure_future(
asyncio.create_task(
self.core.bookmarks.save(self.core.xmpp)
)
self.core.close_tab(self)