python-http_request 0.1.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.1 → python_http_request-0.1.2}/PKG-INFO +1 -1
- {python_http_request-0.1.1 → python_http_request-0.1.2}/http_request/__init__.py +13 -6
- {python_http_request-0.1.1 → python_http_request-0.1.2}/pyproject.toml +1 -1
- {python_http_request-0.1.1 → python_http_request-0.1.2}/LICENSE +0 -0
- {python_http_request-0.1.1 → python_http_request-0.1.2}/http_request/py.typed +0 -0
- {python_http_request-0.1.1 → python_http_request-0.1.2}/readme.md +0 -0
|
@@ -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
|
|
|
@@ -424,7 +431,7 @@ def normalize_request_args(
|
|
|
424
431
|
json: Any = None,
|
|
425
432
|
files: None | Mapping[string, Any] | Iterable[tuple[string, Any]] = None,
|
|
426
433
|
headers: None | Mapping[string, Any] | Iterable[tuple[string, Any]] = None,
|
|
427
|
-
ensure_ascii: bool =
|
|
434
|
+
ensure_ascii: bool = True,
|
|
428
435
|
*,
|
|
429
436
|
async_: bool = False,
|
|
430
437
|
) -> RequestArgs:
|
|
@@ -434,7 +441,7 @@ def normalize_request_args(
|
|
|
434
441
|
elif isinstance(url, URL):
|
|
435
442
|
url = str(url)
|
|
436
443
|
url = complete_url(ensure_str(url))
|
|
437
|
-
if params and (params := urlencode(params)):
|
|
444
|
+
if params and (params := urlencode(params, ensure_ascii=ensure_ascii)):
|
|
438
445
|
urlp = urlparse(url)
|
|
439
446
|
if query := urlp.query:
|
|
440
447
|
params = query + "&" + params
|
|
@@ -476,7 +483,7 @@ def normalize_request_args(
|
|
|
476
483
|
data = dumps(data, default=json_default).encode(charset)
|
|
477
484
|
elif isinstance(data, (Mapping, Sequence)):
|
|
478
485
|
if data:
|
|
479
|
-
data = urlencode(data, charset).encode(charset)
|
|
486
|
+
data = urlencode(data, charset, ensure_ascii=ensure_ascii).encode(charset)
|
|
480
487
|
if mimetype != "application/x-www-form-urlencoded":
|
|
481
488
|
headers_["content-type"] = "application/x-www-form-urlencoded"
|
|
482
489
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|