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: else:
self.api.run_command('/help exec') self.api.run_command('/help exec')
return 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): class Plugin(BasePlugin):
def init(self): def init(self):
if self.config.get('initial_connect', True): if self.config.get('initial_connect', True):
asyncio.ensure_future( asyncio.create_task(
self.initial_connect() self.initial_connect()
) )

View file

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

View file

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

View file

@ -91,10 +91,7 @@ Configuration
""" """
from asyncio import ( import asyncio
ensure_future,
gather,
)
from functools import reduce from functools import reduce
from typing import Dict from typing import Dict
@ -174,10 +171,10 @@ class Plugin(BasePlugin):
] ]
for name, handler in handlers: for name, handler in handlers:
self.core.xmpp.del_event_handler(name, handler) self.core.xmpp.del_event_handler(name, handler)
ensure_future(self._stop()) asyncio.create_task(self._stop())
async def _stop(self): async def _stop(self):
await gather( await asyncio.gather(
self.core.xmpp.plugin['xep_0108'].stop(), self.core.xmpp.plugin['xep_0108'].stop(),
self.core.xmpp.plugin['xep_0107'].stop(), self.core.xmpp.plugin['xep_0107'].stop(),
self.core.xmpp.plugin['xep_0196'].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') self.api.information('Invalid JID: %s' % arg, 'Error')
return return
asyncio.ensure_future( asyncio.create_task(
self._get_vcard(jid) self._get_vcard(jid)
) )
@ -290,7 +290,7 @@ class Plugin(BasePlugin):
jid = JID(arg) jid = JID(arg)
except InvalidJID: except InvalidJID:
return self.api.information('Invalid JID: %s' % arg, 'Error') return self.api.information('Invalid JID: %s' % arg, 'Error')
asyncio.ensure_future( asyncio.create_task(
self._get_vcard(jid) self._get_vcard(jid)
) )
@ -301,11 +301,11 @@ class Plugin(BasePlugin):
return return
current = self.api.current_tab().selected_row current = self.api.current_tab().selected_row
if isinstance(current, Resource): if isinstance(current, Resource):
asyncio.ensure_future( asyncio.create_task(
self._get_vcard(JID(current.jid).bare) self._get_vcard(JID(current.jid).bare)
) )
elif isinstance(current, Contact): elif isinstance(current, Contact):
asyncio.ensure_future( asyncio.create_task(
self._get_vcard(current.bare_jid) self._get_vcard(current.bare_jid)
) )

View file

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

View file

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

View file

@ -108,7 +108,7 @@ class HandlerCore:
await self.core.check_bookmark_storage(features) await self.core.check_bookmark_storage(features)
def find_identities(self, _): def find_identities(self, _):
asyncio.ensure_future( asyncio.create_task(
self.core.xmpp['xep_0030'].get_info_from_domain(), self.core.xmpp['xep_0030'].get_info_from_domain(),
) )
@ -1097,7 +1097,7 @@ class HandlerCore:
if config.getbool('enable_user_nick'): if config.getbool('enable_user_nick'):
self.core.xmpp.plugin['xep_0172'].publish_nick( self.core.xmpp.plugin['xep_0172'].publish_nick(
nick=self.core.own_nick, callback=dumb_callback) 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 # Start the ping's plugin regular event
self.core.xmpp.set_keepalive_values() 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: if not res and on_false is not None:
on_false() on_false()
asyncio.ensure_future( asyncio.create_task(
xmpp.plugin['xep_0030'].get_info(jid=jid, callback=_cb) xmpp.plugin['xep_0030'].get_info(jid=jid, callback=_cb)
) )

View file

@ -321,7 +321,7 @@ class MAMFiller:
self.tab = tab self.tab = tab
self.logger = logger self.logger = logger
logger.fd_busy(tab.jid) 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.done = asyncio.Event()
self.limit = limit self.limit = limit
self.result = 0 self.result = 0

View file

@ -109,7 +109,7 @@ def join_groupchat(
xmpp.plugin['xep_0045'].rooms[jid] = {} xmpp.plugin['xep_0045'].rooms[jid] = {}
xmpp.plugin['xep_0045'].our_nicks[jid] = to.resource 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) 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"): if hasattr(self.input, "reset_completion"):
self.input.reset_completion() self.input.reset_completion()
if asyncio.iscoroutinefunction(func): if asyncio.iscoroutinefunction(func):
asyncio.ensure_future(func(arg)) asyncio.create_task(func(arg))
else: else:
func(arg) func(arg)
return True return True
@ -979,7 +979,7 @@ class ChatTab(Tab):
def on_scroll_up(self): def on_scroll_up(self):
if not self.query_status: if not self.query_status:
from poezio.log_loader import LogLoader from poezio.log_loader import LogLoader
asyncio.ensure_future( asyncio.create_task(
LogLoader(logger, self, config.getbool('use_log')).scroll_requested() LogLoader(logger, self, config.getbool('use_log')).scroll_requested()
) )
return self.text_win.scroll_up(self.text_win.height - 1) return self.text_win.scroll_up(self.text_win.height - 1)
@ -1036,10 +1036,10 @@ class OneToOneTab(ChatTab):
if mam_filler.result == 0: if mam_filler.result == 0:
self.handle_message(initial) self.handle_message(initial)
asyncio.ensure_future(fallback_no_mam()) asyncio.create_task(fallback_no_mam())
elif use_log and initial: elif use_log and initial:
self.handle_message(initial, display=False) self.handle_message(initial, display=False)
asyncio.ensure_future( asyncio.create_task(
LogLoader(logger, self, use_log).tab_open() LogLoader(logger, self, use_log).tab_open()
) )

View file

@ -96,7 +96,7 @@ class BookmarksTab(Tab):
if bm in self.bookmarks: if bm in self.bookmarks:
self.bookmarks.remove(bm) self.bookmarks.remove(bm)
asyncio.ensure_future( asyncio.create_task(
self.save_routine() 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 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() self.core.close_tab()
def send_config(self, form: Form) -> None: def send_config(self, form: Form) -> None:
""" """
The user sends their config to the server 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() self.core.close_tab()
def join(self) -> None: 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) logger, self, config.get_by_tabname('use_log', self.general_jid)
).tab_open()) ).tab_open())
@ -1513,7 +1513,7 @@ class MucTab(ChatTab):
bookmark = self.core.bookmarks[self.jid] bookmark = self.core.bookmarks[self.jid]
if bookmark: if bookmark:
bookmark.autojoin = False bookmark.autojoin = False
asyncio.ensure_future( asyncio.create_task(
self.core.bookmarks.save(self.core.xmpp) self.core.bookmarks.save(self.core.xmpp)
) )
self.core.close_tab(self) self.core.close_tab(self)