Skip to content

Commit

Permalink
fix pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
atimin committed Jul 26, 2023
1 parent 71bd691 commit 93e1068
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions reduct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(
api_token: Optional[str] = None,
timeout: Optional[float] = None,
extra_headers: Optional[Dict[str, str]] = None,
session: Optional[ClientSession] = None,
**kwargs,
):
"""
Constructor
Expand All @@ -110,13 +110,14 @@ def __init__(
api_token: API token if the storage uses it for authorization
timeout: total timeout for connection, request and response in seconds
extra_headers: extra headers to send with each request
Kwargs:
session: an external aiohttp session to use for requests
Examples:
>>> client = Client("http://127.0.0.1:8383")
>>> info = await client.info()
"""
self._http = HttpClient(
url.rstrip("/"), api_token, timeout, extra_headers, session
url.rstrip("/"), api_token, timeout, extra_headers, **kwargs
)

async def __aenter__(self):
Expand Down
16 changes: 10 additions & 6 deletions reduct/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(
api_token: Optional[str] = None,
timeout: Optional[float] = None,
extra_headers: Optional[Dict[str, str]] = None,
session: Optional[aiohttp.ClientSession] = None,
**kwargs,
):
self._url = url + API_PREFIX
self._api_token = api_token
Expand All @@ -34,7 +34,7 @@ def __init__(

self._timeout = ClientTimeout(timeout)
self._api_version = None
self._session = session
self._session = kwargs.pop("session", None)

@asynccontextmanager
async def request(
Expand Down Expand Up @@ -70,25 +70,29 @@ async def request(
timeout=self._timeout, connector=connector
) as session:
async with self._request(
expect100, extra_headers, kwargs, method, path, session
method, path, session, extra_headers, expect100=expect100, **kwargs
) as response:
yield response
else:
async with self._request(
expect100, extra_headers, kwargs, method, path, self._session
method,
path,
self._session,
extra_headers,
expect100=expect100,
**kwargs,
) as response:
yield response

@asynccontextmanager
async def _request(
self, expect100, extra_headers, kwargs, method, path, session
self, method, path, session, extra_headers, **kwargs
) -> AsyncIterator[ClientResponse]:
try:
async with session.request(
method,
f"{self._url}{path.strip()}",
headers=dict(self._headers, **extra_headers),
expect100=expect100,
**kwargs,
) as response:
if self._api_version is None:
Expand Down
1 change: 1 addition & 0 deletions tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ async def test__me(client):

@pytest.mark.asyncio
async def test__with(url, api_token):
"""Should create a client with context manager"""
async with Client(url, api_token=api_token) as client:
bucket = await client.create_bucket("bucket-1", exist_ok=True)
await bucket.info()

0 comments on commit 93e1068

Please sign in to comment.