python-http_request 0.1.0.1__tar.gz → 0.1.2__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.
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/PKG-INFO +3 -3
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/http_request/__init__.py +14 -11
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/pyproject.toml +3 -3
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/LICENSE +0 -0
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/http_request/py.typed +0 -0
- {python_http_request-0.1.0.1 → python_http_request-0.1.2}/readme.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-http_request
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Python http response utils.
|
|
5
5
|
Home-page: https://github.com/ChenyangGao/python-modules/tree/main/python-http_request
|
|
6
6
|
License: MIT
|
|
@@ -20,10 +20,10 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
20
20
|
Classifier: Topic :: Software Development
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
-
Requires-Dist: http_response (>=0.0.
|
|
23
|
+
Requires-Dist: http_response (>=0.0.7)
|
|
24
24
|
Requires-Dist: orjson
|
|
25
25
|
Requires-Dist: python-asynctools (>=0.1.3)
|
|
26
|
-
Requires-Dist: python-dicttools (>=0.0.
|
|
26
|
+
Requires-Dist: python-dicttools (>=0.0.2)
|
|
27
27
|
Requires-Dist: python-ensure (>=0.0.1)
|
|
28
28
|
Requires-Dist: python-filewrap (>=0.2.8)
|
|
29
29
|
Requires-Dist: python-texttools (>=0.0.4)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 1,
|
|
5
|
+
__version__ = (0, 1, 2)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"SupportsGeturl", "url_origin", "complete_url", "ensure_ascii_url",
|
|
8
8
|
"urlencode", "cookies_str_to_dict", "headers_str_to_dict_by_lines",
|
|
@@ -124,6 +124,7 @@ def urlencode(
|
|
|
124
124
|
/,
|
|
125
125
|
encoding: str = "utf-8",
|
|
126
126
|
errors: str = "strict",
|
|
127
|
+
ensure_ascii: bool = True,
|
|
127
128
|
) -> str:
|
|
128
129
|
if isinstance(payload, str):
|
|
129
130
|
return payload
|
|
@@ -139,7 +140,10 @@ def urlencode(
|
|
|
139
140
|
k = str(k, encoding, errors)
|
|
140
141
|
else:
|
|
141
142
|
k = str(k)
|
|
142
|
-
|
|
143
|
+
if ensure_ascii:
|
|
144
|
+
yield quote(k)
|
|
145
|
+
else:
|
|
146
|
+
yield k.translate(QUERY_KEY_TRANSTAB)
|
|
143
147
|
yield "="
|
|
144
148
|
if v is True:
|
|
145
149
|
yield "true"
|
|
@@ -158,7 +162,10 @@ def urlencode(
|
|
|
158
162
|
v = json_dumps(v, default=json_default).decode("utf-8")
|
|
159
163
|
else:
|
|
160
164
|
v = str(v)
|
|
161
|
-
|
|
165
|
+
if ensure_ascii:
|
|
166
|
+
yield quote(v)
|
|
167
|
+
else:
|
|
168
|
+
yield v.replace("&", "%26")
|
|
162
169
|
return "".join(encode_iter(iter_items(payload)))
|
|
163
170
|
|
|
164
171
|
|
|
@@ -290,12 +297,10 @@ def encode_multipart_data(
|
|
|
290
297
|
def encode_iter() -> Iterator[Buffer]:
|
|
291
298
|
if data:
|
|
292
299
|
for name, value in iter_items(data):
|
|
293
|
-
yield boundary_line
|
|
294
300
|
yield from encode_item(name, value)
|
|
295
301
|
yield b"\r\n"
|
|
296
302
|
if files:
|
|
297
303
|
for name, value in iter_items(files):
|
|
298
|
-
yield boundary_line
|
|
299
304
|
yield from encode_item(name, value, is_file=True)
|
|
300
305
|
yield b"\r\n"
|
|
301
306
|
yield b'--%s--\r\n' % boundary_bytes
|
|
@@ -385,13 +390,11 @@ def encode_multipart_data_async(
|
|
|
385
390
|
async def encode_iter() -> AsyncIterator[Buffer]:
|
|
386
391
|
if data:
|
|
387
392
|
for name, value in iter_items(data):
|
|
388
|
-
yield boundary_line
|
|
389
393
|
async for line in encode_item(name, value):
|
|
390
394
|
yield line
|
|
391
395
|
yield b"\r\n"
|
|
392
396
|
if files:
|
|
393
397
|
for name, value in iter_items(files):
|
|
394
|
-
yield boundary_line
|
|
395
398
|
async for line in encode_item(name, value, is_file=True):
|
|
396
399
|
yield line
|
|
397
400
|
yield b"\r\n"
|
|
@@ -428,7 +431,7 @@ def normalize_request_args(
|
|
|
428
431
|
json: Any = None,
|
|
429
432
|
files: None | Mapping[string, Any] | Iterable[tuple[string, Any]] = None,
|
|
430
433
|
headers: None | Mapping[string, Any] | Iterable[tuple[string, Any]] = None,
|
|
431
|
-
ensure_ascii: bool =
|
|
434
|
+
ensure_ascii: bool = True,
|
|
432
435
|
*,
|
|
433
436
|
async_: bool = False,
|
|
434
437
|
) -> RequestArgs:
|
|
@@ -438,7 +441,7 @@ def normalize_request_args(
|
|
|
438
441
|
elif isinstance(url, URL):
|
|
439
442
|
url = str(url)
|
|
440
443
|
url = complete_url(ensure_str(url))
|
|
441
|
-
if params and (params := urlencode(params)):
|
|
444
|
+
if params and (params := urlencode(params, ensure_ascii=ensure_ascii)):
|
|
442
445
|
urlp = urlparse(url)
|
|
443
446
|
if query := urlp.query:
|
|
444
447
|
params = query + "&" + params
|
|
@@ -453,7 +456,7 @@ def normalize_request_args(
|
|
|
453
456
|
content_type = headers_.get("content-type", "")
|
|
454
457
|
charset = get_charset(content_type)
|
|
455
458
|
mimetype = get_mimetype(charset).lower()
|
|
456
|
-
if files
|
|
459
|
+
if files:
|
|
457
460
|
headers2, data = encode_multipart_data(
|
|
458
461
|
cast(None | Mapping[string, Any] | Iterable[tuple[string, Any]], data),
|
|
459
462
|
files,
|
|
@@ -480,7 +483,7 @@ def normalize_request_args(
|
|
|
480
483
|
data = dumps(data, default=json_default).encode(charset)
|
|
481
484
|
elif isinstance(data, (Mapping, Sequence)):
|
|
482
485
|
if data:
|
|
483
|
-
data = urlencode(data, charset).encode(charset)
|
|
486
|
+
data = urlencode(data, charset, ensure_ascii=ensure_ascii).encode(charset)
|
|
484
487
|
if mimetype != "application/x-www-form-urlencoded":
|
|
485
488
|
headers_["content-type"] = "application/x-www-form-urlencoded"
|
|
486
489
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python-http_request"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
description = "Python http response utils."
|
|
5
5
|
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -27,10 +27,10 @@ include = [
|
|
|
27
27
|
|
|
28
28
|
[tool.poetry.dependencies]
|
|
29
29
|
python = "^3.12"
|
|
30
|
-
http_response = ">=0.0.
|
|
30
|
+
http_response = ">=0.0.7"
|
|
31
31
|
orjson = "*"
|
|
32
32
|
python-asynctools = ">=0.1.3"
|
|
33
|
-
python-dicttools = ">=0.0.
|
|
33
|
+
python-dicttools = ">=0.0.2"
|
|
34
34
|
python-ensure = ">=0.0.1"
|
|
35
35
|
python-filewrap = ">=0.2.8"
|
|
36
36
|
python-texttools = ">=0.0.4"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|