From 5dd2db96f1278ae7d7dae697a2ac77c128a6cdad Mon Sep 17 00:00:00 2001 From: Alexey Timin Date: Wed, 26 Jul 2023 15:17:23 +0200 Subject: [PATCH] fix format --- reduct/client.py | 24 +++++++++++++----------- reduct/http.py | 40 +++++++++++++++++++++++----------------- tests/client_test.py | 2 +- tests/conftest.py | 1 + 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/reduct/client.py b/reduct/client.py index be5ba2d..fce0925 100644 --- a/reduct/client.py +++ b/reduct/client.py @@ -95,12 +95,12 @@ class Client: """HTTP Client for Reduct Storage HTTP API""" def __init__( - self, - url: str, - api_token: Optional[str] = None, - timeout: Optional[float] = None, - extra_headers: Optional[Dict[str, str]] = None, - session: Optional[ClientSession] = None, + self, + url: str, + api_token: Optional[str] = None, + timeout: Optional[float] = None, + extra_headers: Optional[Dict[str, str]] = None, + session: Optional[ClientSession] = None, ): """ Constructor @@ -115,7 +115,9 @@ def __init__( >>> client = Client("http://127.0.0.1:8383") >>> info = await client.info() """ - self._http = HttpClient(url.rstrip("/"), api_token, timeout, extra_headers, session) + self._http = HttpClient( + url.rstrip("/"), api_token, timeout, extra_headers, session + ) async def __aenter__(self): self._http._session = ClientSession(timeout=self._http._timeout) @@ -163,10 +165,10 @@ async def get_bucket(self, name: str) -> Bucket: return Bucket(name, self._http) async def create_bucket( - self, - name: str, - settings: Optional[BucketSettings] = None, - exist_ok: bool = False, + self, + name: str, + settings: Optional[BucketSettings] = None, + exist_ok: bool = False, ) -> Bucket: """ Create a new bucket diff --git a/reduct/http.py b/reduct/http.py index fe6efe5..bb97594 100644 --- a/reduct/http.py +++ b/reduct/http.py @@ -17,12 +17,12 @@ class HttpClient: FILE_SIZE_FOR_100_CONTINUE = 256_000 def __init__( - self, - url: str, - api_token: Optional[str] = None, - timeout: Optional[float] = None, - extra_headers: Optional[Dict[str, str]] = None, - session: Optional[aiohttp.ClientSession] = None, + self, + url: str, + api_token: Optional[str] = None, + timeout: Optional[float] = None, + extra_headers: Optional[Dict[str, str]] = None, + session: Optional[aiohttp.ClientSession] = None, ): self._url = url + API_PREFIX self._api_token = api_token @@ -38,7 +38,7 @@ def __init__( @asynccontextmanager async def request( - self, method: str, path: str = "", **kwargs + self, method: str, path: str = "", **kwargs ) -> AsyncIterator[ClientResponse]: """HTTP request with ReductError exception""" @@ -67,23 +67,29 @@ async def request( if self._session is None: connector = aiohttp.TCPConnector(force_close=True) async with aiohttp.ClientSession( - timeout=self._timeout, connector=connector + timeout=self._timeout, connector=connector ) as session: - async with self._request(expect100, extra_headers, kwargs, method, path, session) as response: + async with self._request( + expect100, extra_headers, kwargs, method, path, session + ) as response: yield response else: - async with self._request(expect100, extra_headers, kwargs, method, path, self._session) as response: + async with self._request( + expect100, extra_headers, kwargs, method, path, self._session + ) as response: yield response @asynccontextmanager - async def _request(self, expect100, extra_headers, kwargs, method, path, session) -> AsyncIterator[ClientResponse]: + async def _request( + self, expect100, extra_headers, kwargs, method, path, session + ) -> AsyncIterator[ClientResponse]: try: async with session.request( - method, - f"{self._url}{path.strip()}", - headers=dict(self._headers, **extra_headers), - expect100=expect100, - **kwargs, + method, + f"{self._url}{path.strip()}", + headers=dict(self._headers, **extra_headers), + expect100=expect100, + **kwargs, ) as response: if self._api_version is None: self._api_version = response.headers.get("x-reduct-api") @@ -108,7 +114,7 @@ async def request_all(self, method: str, path: str = "", **kwargs) -> bytes: return await response.read() async def request_chunked( - self, method: str, path: str = "", chunk_size=1024, **kwargs + self, method: str, path: str = "", chunk_size=1024, **kwargs ) -> AsyncIterator[bytes]: """Http request""" async with self.request(method, path, **kwargs) as response: diff --git a/tests/client_test.py b/tests/client_test.py index 0c3e2e0..ef4b5aa 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -233,4 +233,4 @@ async def test__me(client): async def test__with(url, api_token): async with Client(url, api_token=api_token) as client: bucket = await client.create_bucket("bucket-1", exist_ok=True) - await bucket.info() \ No newline at end of file + await bucket.info() diff --git a/tests/conftest.py b/tests/conftest.py index 61b452e..cc2e91d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,6 +28,7 @@ def _token() -> Optional[str]: api_token = os.getenv("RS_API_TOKEN", default=None) return api_token + @pytest_asyncio.fixture(name="client") async def _make_client(url, api_token): client = Client(url, api_token=api_token)