libentry 1.21.3__py3-none-any.whl → 1.21.4__py3-none-any.whl

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.
libentry/api.py CHANGED
@@ -14,7 +14,7 @@ import asyncio
14
14
  from dataclasses import dataclass, field
15
15
  from time import sleep
16
16
  from typing import Any, AsyncIterable, Callable, Iterable, List, Literal, Mapping, Optional, Tuple, Union
17
- from urllib.parse import urljoin
17
+ from urllib.parse import urlencode, urljoin
18
18
 
19
19
  import httpx
20
20
  from urllib3 import PoolManager
@@ -217,10 +217,7 @@ class BaseClient:
217
217
  stream: bool,
218
218
  verify: bool,
219
219
  ) -> Union[bytes, Iterable[bytes]]:
220
- if headers is None:
221
- headers = self.headers
222
- else:
223
- headers = {**self.headers, **headers}
220
+ headers = self.headers if headers is None else {**self.headers, **headers}
224
221
  response = self.URLLIB3_POOL[int(verify)].request(
225
222
  method=method,
226
223
  url=url,
@@ -309,10 +306,7 @@ class BaseClient:
309
306
  stream: bool,
310
307
  verify: bool,
311
308
  ):
312
- if headers is None:
313
- headers = self.headers
314
- else:
315
- headers = {**self.headers, **headers}
309
+ headers = self.headers if headers is None else {**self.headers, **headers}
316
310
  if not stream:
317
311
  async with httpx.AsyncClient(headers=headers, verify=verify) as client:
318
312
  response = await client.request(
@@ -392,6 +386,19 @@ class BaseClient:
392
386
 
393
387
  class APIClient(BaseClient):
394
388
 
389
+ @staticmethod
390
+ def _encode_params(data):
391
+ result = []
392
+ for k, v in data.items():
393
+ if v is not None:
394
+ result.append(
395
+ (
396
+ k.encode("utf-8") if isinstance(k, str) else k,
397
+ v.encode("utf-8") if isinstance(v, str) else v,
398
+ )
399
+ )
400
+ return urlencode(result, doseq=True)
401
+
395
402
  def request(
396
403
  self,
397
404
  method: Literal["GET", "POST"],
@@ -417,7 +424,10 @@ class APIClient(BaseClient):
417
424
  headers = {}
418
425
  accept = headers["Accept"] if "Accept" in headers else self.headers["Accept"]
419
426
  headers["Accept"] = accept + f"; stream={int(stream)}"
420
- body = json.dumps(json_data) if json_data is not None else None
427
+ if "Content-Type" in headers and headers["Content-Type"] == "application/x-www-form-urlencoded":
428
+ body = self._encode_params(json_data)
429
+ else:
430
+ body = json.dumps(json_data) if json_data is not None else None
421
431
  content = super().request(
422
432
  method,
423
433
  full_url,
@@ -571,7 +581,10 @@ class APIClient(BaseClient):
571
581
  headers = {}
572
582
  accept = headers["Accept"] if "Accept" in headers else self.headers["Accept"]
573
583
  headers["Accept"] = accept + f"; stream={int(stream)}"
574
- body = json.dumps(json_data) if json_data is not None else None
584
+ if "Content-Type" in headers and headers["Content-Type"] == "application/x-www-form-urlencoded":
585
+ body = self._encode_params(json_data)
586
+ else:
587
+ body = json.dumps(json_data) if json_data is not None else None
575
588
  content = await super().request_async(
576
589
  method,
577
590
  full_url,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libentry
3
- Version: 1.21.3
3
+ Version: 1.21.4
4
4
  Summary: Entries for experimental utilities.
5
5
  Home-page: https://github.com/XoriieInpottn/libentry
6
6
  Author: xi
@@ -1,5 +1,5 @@
1
1
  libentry/__init__.py,sha256=ko2YBIIx5H3dD0tedBkialzJGEDczFaP_PZmT1cIlak,148
2
- libentry/api.py,sha256=ei67QL_PEMs1J_utCuh5MifPbAw17BOYnaYtc8d35UY,22923
2
+ libentry/api.py,sha256=-8rvVdOOuJQ4vL4hYZcNMm8sUoSgv2r41QLNQ-Ny8vw,23607
3
3
  libentry/argparse.py,sha256=NxzXV-jBN51ReZsNs5aeyOfzwYQ5A5nJ95rWoa-FYCs,10415
4
4
  libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
5
5
  libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
@@ -15,10 +15,10 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
15
15
  libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
16
16
  libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
17
17
  libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
18
- libentry-1.21.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
- libentry-1.21.3.dist-info/METADATA,sha256=43wuxNjrLdOaLoW5E55_JEMhGAPAAVTFe5WltenN7L0,813
20
- libentry-1.21.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
21
- libentry-1.21.3.dist-info/entry_points.txt,sha256=vgHmJZhM-kqM7U9S179UwDD3pM232tpzJ5NntncXi_8,62
22
- libentry-1.21.3.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
23
- libentry-1.21.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
24
- libentry-1.21.3.dist-info/RECORD,,
18
+ libentry-1.21.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
+ libentry-1.21.4.dist-info/METADATA,sha256=54r6arFvYSQnlyDjhXivn-HYRtM4cEt0kyPRz5sK5YY,813
20
+ libentry-1.21.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
21
+ libentry-1.21.4.dist-info/entry_points.txt,sha256=vgHmJZhM-kqM7U9S179UwDD3pM232tpzJ5NntncXi_8,62
22
+ libentry-1.21.4.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
23
+ libentry-1.21.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
24
+ libentry-1.21.4.dist-info/RECORD,,