xn-client 0.0.3.dev2__tar.gz → 0.0.3.dev4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/.pre-commit-config.yaml +1 -0
- {xn_client-0.0.3.dev2/xn_client.egg-info → xn_client-0.0.3.dev4}/PKG-INFO +1 -1
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/pyproject.toml +3 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/x_client/aiohttp.py +20 -8
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/x_client/http.py +6 -3
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4/xn_client.egg-info}/PKG-INFO +1 -1
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/.gitignore +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/README.md +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/makefile +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/setup.cfg +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/tests/__init__.py +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/tests/test_request.py +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/x_client/__init__.py +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/xn_client.egg-info/SOURCES.txt +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/xn_client.egg-info/dependency_links.txt +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/xn_client.egg-info/requires.txt +0 -0
- {xn_client-0.0.3.dev2 → xn_client-0.0.3.dev4}/xn_client.egg-info/top_level.txt +0 -0
|
@@ -35,6 +35,9 @@ local_scheme = "no-local-version"
|
|
|
35
35
|
[tool.ruff]
|
|
36
36
|
line-length = 120
|
|
37
37
|
|
|
38
|
+
[tool.ruff.format]
|
|
39
|
+
preview = true
|
|
40
|
+
|
|
38
41
|
[tool.pytest.ini_options]
|
|
39
42
|
asyncio_mode = "auto"
|
|
40
43
|
asyncio_default_fixture_loop_scope = "module" # , "session", "class", "package", "function"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
1
3
|
from aiohttp import ClientSession, ClientResponse
|
|
2
4
|
from aiohttp.http_exceptions import HttpProcessingError
|
|
3
5
|
|
|
@@ -17,24 +19,34 @@ class Client:
|
|
|
17
19
|
async def close(self):
|
|
18
20
|
await self.session.close()
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
# noinspection PyMethodMayBeStatic
|
|
23
|
+
def _prehook(self, _payload: dict = None):
|
|
24
|
+
return {}
|
|
25
|
+
|
|
26
|
+
async def _get(self, url: str, params: dict = None):
|
|
27
|
+
asyncio.get_running_loop()
|
|
28
|
+
resp = await self.session.get(url, params=params, headers=self._prehook(params))
|
|
22
29
|
return await self._proc(resp)
|
|
23
30
|
|
|
24
|
-
async def _post(self, url: str, data: dict = None
|
|
31
|
+
async def _post(self, url: str, data: dict = None):
|
|
25
32
|
dt = {"json" if isinstance(data, dict) else "data": data}
|
|
26
|
-
resp = await self.session.post(url, **dt,
|
|
33
|
+
resp = await self.session.post(url, **dt, headers=self._prehook(data))
|
|
27
34
|
return await self._proc(resp)
|
|
28
35
|
|
|
29
|
-
async def _delete(self, url: str, params: dict = None
|
|
30
|
-
resp: ClientResponse = await self.session.delete(url, params=params,
|
|
36
|
+
async def _delete(self, url: str, params: dict = None):
|
|
37
|
+
resp: ClientResponse = await self.session.delete(url, params=params, headers=self._prehook(params))
|
|
31
38
|
return await self._proc(resp)
|
|
32
39
|
|
|
33
|
-
async def _proc(self, resp: ClientResponse,
|
|
40
|
+
async def _proc(self, resp: ClientResponse, data_key: str = None, body=None) -> dict | str:
|
|
34
41
|
if not str(resp.status).startswith("2"):
|
|
35
42
|
if resp.status == 404:
|
|
36
43
|
raise HttpNotFound()
|
|
37
44
|
raise HttpProcessingError(code=resp.status, message=await resp.text())
|
|
38
45
|
if resp.content_type.endswith("/json"):
|
|
39
|
-
|
|
46
|
+
data = await resp.json()
|
|
47
|
+
if data_key:
|
|
48
|
+
if res := data.get(data_key):
|
|
49
|
+
return res
|
|
50
|
+
raise HttpProcessingError()
|
|
51
|
+
return data
|
|
40
52
|
return await resp.text()
|
|
@@ -31,9 +31,12 @@ class Client:
|
|
|
31
31
|
return self.__resp()
|
|
32
32
|
|
|
33
33
|
def __resp(self) -> dict:
|
|
34
|
-
resp = self.cn.getresponse()
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
resp = self.cn.getresponse().read()
|
|
35
|
+
try:
|
|
36
|
+
body = loads(resp)
|
|
37
|
+
except Exception:
|
|
38
|
+
body = brotli.decompress(resp)
|
|
39
|
+
return body
|
|
37
40
|
|
|
38
41
|
def close(self):
|
|
39
42
|
self.cn.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|