From 2c97a6cf47e69fbdd367caf863fb8d82aec074f2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Aug 2020 02:24:56 +0200 Subject: [PATCH] BREAKING: Remove session property from commanddata.py --- royalnet/commands/commanddata.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/royalnet/commands/commanddata.py b/royalnet/commands/commanddata.py index 72ea82eb..fe8d0420 100644 --- a/royalnet/commands/commanddata.py +++ b/royalnet/commands/commanddata.py @@ -16,36 +16,11 @@ log = logging.getLogger(__name__) class CommandData: def __init__(self, command): self.command = command - self._session = None - - # TODO: make this asyncronous... somehow? - @property - def session(self): - if self._session is None: - if self.command.serf.alchemy is None: - raise UnsupportedError("'alchemy' is not enabled on this Royalnet instance") - log.debug("Creating Session...") - self._session = self.command.serf.alchemy.Session() - return self._session @property def loop(self): return self.command.serf.loop - async def session_commit(self): - """Asyncronously commit the :attr:`.session` of this object.""" - if self._session: - log.warning("Session had to be created to be committed") - # noinspection PyUnresolvedReferences - log.debug("Committing Session...") - await ru.asyncify(self.session.commit) - - async def session_close(self): - """Asyncronously close the :attr:`.session` of this object.""" - if self._session is not None: - log.debug("Closing Session...") - await ru.asyncify(self._session.close) - async def reply(self, text: str) -> None: """Send a text message to the channel where the call was made. @@ -84,7 +59,8 @@ class CommandData: Parameters: alias: the Alias to search for.""" - return await User.find(self.command.serf.alchemy, self.session, alias) + async with self.command.alchemy.session_acm() as session: + return await User.find(self.command.serf.alchemy, session, alias) @contextlib.asynccontextmanager async def keyboard(self, text, keys: List["KeyboardKey"]):