xn-client 0.0.3.dev3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xn-client
3
- Version: 0.0.3.dev3
3
+ Version: 0.0.3.dev4
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/XyncNet/x-client
@@ -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
 
@@ -22,7 +24,8 @@ class Client:
22
24
  return {}
23
25
 
24
26
  async def _get(self, url: str, params: dict = None):
25
- resp: ClientResponse = await self.session.get(url, params=params, headers=self._prehook(params))
27
+ asyncio.get_running_loop()
28
+ resp = await self.session.get(url, params=params, headers=self._prehook(params))
26
29
  return await self._proc(resp)
27
30
 
28
31
  async def _post(self, url: str, data: dict = None):
@@ -34,11 +37,16 @@ class Client:
34
37
  resp: ClientResponse = await self.session.delete(url, params=params, headers=self._prehook(params))
35
38
  return await self._proc(resp)
36
39
 
37
- async def _proc(self, resp: ClientResponse, data=None) -> dict | str:
40
+ async def _proc(self, resp: ClientResponse, data_key: str = None, body=None) -> dict | str:
38
41
  if not str(resp.status).startswith("2"):
39
42
  if resp.status == 404:
40
43
  raise HttpNotFound()
41
44
  raise HttpProcessingError(code=resp.status, message=await resp.text())
42
45
  if resp.content_type.endswith("/json"):
43
- return await resp.json()
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
44
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
- body = brotli.decompress(resp.read())
36
- return loads(body)
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xn-client
3
- Version: 0.0.3.dev3
3
+ Version: 0.0.3.dev4
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/XyncNet/x-client
File without changes
File without changes
File without changes