Skip to content
Snippets Groups Projects
Commit 9c92af97 authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Add with-statement support for handles

parent b9e7e0f0
No related branches found
No related tags found
1 merge request!73Clive integration related fixes
......@@ -17,7 +17,7 @@ from beekeepy.exceptions import (
BeekeeperFailedToStartNotReadyOnTimeError,
BeekeeperIsNotRunningError,
)
from helpy import ContextAsync, ContextSync, HttpUrl
from helpy import HttpUrl
from helpy._communication.universal_notification_server import (
UniversalNotificationServer,
)
......@@ -195,7 +195,7 @@ class BeekeeperCommon(BeekeeperNotificationCallbacks, ABC):
def _get_settings(self) -> Settings: ...
class Beekeeper(BeekeeperCommon, SyncRemoteBeekeeper, ContextSync["Beekeeper"]):
class Beekeeper(BeekeeperCommon, SyncRemoteBeekeeper):
def run(self, *, additional_cli_arguments: BeekeeperArguments | None = None) -> None:
self._clear_session()
with self.update_settings() as settings:
......@@ -217,15 +217,12 @@ class Beekeeper(BeekeeperCommon, SyncRemoteBeekeeper, ContextSync["Beekeeper"]):
self.run()
return self
def _finally(self) -> None:
self.teardown()
def teardown(self) -> None:
self._close()
super().teardown()
class AsyncBeekeeper(BeekeeperCommon, AsyncRemoteBeekeeper, ContextAsync["AsyncBeekeeper"]):
class AsyncBeekeeper(BeekeeperCommon, AsyncRemoteBeekeeper):
def run(self, *, additional_cli_arguments: BeekeeperArguments | None = None) -> None:
self._clear_session()
with self.update_settings() as settings:
......@@ -247,9 +244,6 @@ class AsyncBeekeeper(BeekeeperCommon, AsyncRemoteBeekeeper, ContextAsync["AsyncB
self.run()
return self
async def _afinally(self) -> None:
self.teardown()
def teardown(self) -> None:
self._close()
super().teardown()
......@@ -9,6 +9,7 @@ from helpy._communication.aiohttp_communicator import AioHttpCommunicator
from helpy._communication.request_communicator import RequestCommunicator
from helpy._handles.build_json_rpc_call import build_json_rpc_call
from helpy._handles.settings import Settings
from helpy._interfaces.context import SelfContextAsync, SelfContextSync
from helpy._interfaces.settings_holder import UniqueSettingsHolder
from helpy._interfaces.stopwatch import Stopwatch
from schemas.jsonrpc import ExpectResultT, JSONRPCResult, get_response_model
......@@ -117,7 +118,7 @@ class AbstractHandle(UniqueSettingsHolder[Settings], ABC, Generic[ApiT]):
self._overseer.teardown()
class AbstractAsyncHandle(AbstractHandle[ApiT], ABC):
class AbstractAsyncHandle(AbstractHandle[ApiT], SelfContextAsync, ABC):
"""Base class for service handlers that uses asynchronous communication."""
async def _async_send(
......@@ -143,8 +144,11 @@ class AbstractAsyncHandle(AbstractHandle[ApiT], ABC):
async def batch(self, *, delay_error_on_data_access: bool = False) -> AsyncBatchHandle[Any]:
"""Returns async batch handle."""
async def _afinally(self) -> None:
self.teardown()
class AbstractSyncHandle(AbstractHandle[ApiT], ABC):
class AbstractSyncHandle(AbstractHandle[ApiT], SelfContextSync, ABC):
"""Base class for service handlers that uses synchronous communication."""
def _send(self, *, endpoint: str, params: str, expected_type: type[ExpectResultT]) -> JSONRPCResult[ExpectResultT]:
......@@ -167,3 +171,6 @@ class AbstractSyncHandle(AbstractHandle[ApiT], ABC):
@abstractmethod
def batch(self, *, delay_error_on_data_access: bool = False) -> SyncBatchHandle[Any]:
"""Returns sync batch handle."""
def _finally(self) -> None:
self.teardown()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment