Skip to content
Snippets Groups Projects

Beekeepy: Add session holder class and session token handling

Merged Krzysztof Mochocki requested to merge kmochocki/beekeepy into develop
Compare and Show latest version
34 files
+ 617
141
Compare changes
  • Side-by-side
  • Inline
Files
34
@@ -3,12 +3,15 @@ from __future__ import annotations
import asyncio
import time
from abc import ABC, abstractmethod
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any
from helpy._communication.settings import CommunicationSettings
from helpy.exceptions import CommunicationError
if TYPE_CHECKING:
from collections.abc import Iterator
from helpy._interfaces.url import HttpUrl
@@ -16,7 +19,7 @@ class AbstractCommunicator(ABC):
"""Provides basic interface for communicators, which can implement communications using different way."""
def __init__(self, *args: Any, settings: CommunicationSettings | None = None, **kwargs: Any) -> None:
self.__settings = settings or CommunicationSettings()
self.__settings = (settings or CommunicationSettings()).copy()
super().__init__(*args, **kwargs)
@property
@@ -56,3 +59,9 @@ class AbstractCommunicator(ABC):
if not (ok_status_code_lower_bound <= status_code <= ok_status_code_upper_bound):
raise CommunicationError(f"{status_code=}", f"{sent=}", f"{received=}")
@contextmanager
def restore_settings(self) -> Iterator[None]:
before = self.settings.copy()
yield
self.__settings = before
Loading