python-http_request 0.0.4.1__tar.gz → 0.0.5.1__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.0.4.1 → python_http_request-0.0.5.1}/PKG-INFO +2 -2
- {python_http_request-0.0.4.1 → python_http_request-0.0.5.1}/http_request/__init__.py +14 -19
- {python_http_request-0.0.4.1 → python_http_request-0.0.5.1}/pyproject.toml +2 -2
- {python_http_request-0.0.4.1 → python_http_request-0.0.5.1}/LICENSE +0 -0
- {python_http_request-0.0.4.1 → python_http_request-0.0.5.1}/http_request/py.typed +0 -0
- {python_http_request-0.0.4.1 → python_http_request-0.0.5.1}/readme.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-http_request
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5.1
|
|
4
4
|
Summary: Python http response utils.
|
|
5
5
|
Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-http_request
|
|
6
6
|
License: MIT
|
|
@@ -23,7 +23,7 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
24
|
Requires-Dist: integer_tool
|
|
25
25
|
Requires-Dist: python-asynctools
|
|
26
|
-
Requires-Dist: python-filewrap
|
|
26
|
+
Requires-Dist: python-filewrap (>=0.1)
|
|
27
27
|
Requires-Dist: python-texttools
|
|
28
28
|
Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-http_request
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 0,
|
|
5
|
+
__version__ = (0, 0, 5)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"SupportsGeturl", "url_origin", "complete_url", "cookies_str_to_dict", "headers_str_to_dict",
|
|
8
8
|
"encode_multipart_data", "encode_multipart_data_async",
|
|
@@ -16,7 +16,7 @@ from urllib.parse import quote, urlsplit, urlunsplit
|
|
|
16
16
|
from uuid import uuid4
|
|
17
17
|
|
|
18
18
|
from asynctools import ensure_aiter, async_chain
|
|
19
|
-
from filewrap import bio_chunk_iter, bio_chunk_async_iter, SupportsRead
|
|
19
|
+
from filewrap import bio_chunk_iter, bio_chunk_async_iter, Buffer, SupportsRead
|
|
20
20
|
from integer_tool import int_to_bytes
|
|
21
21
|
from texttools import text_to_dict
|
|
22
22
|
|
|
@@ -73,8 +73,8 @@ def headers_str_to_dict(
|
|
|
73
73
|
return text_to_dict(headers.strip(), kv_sep, entry_sep)
|
|
74
74
|
|
|
75
75
|
|
|
76
|
-
def ensure_bytes(s, /) ->
|
|
77
|
-
if isinstance(s,
|
|
76
|
+
def ensure_bytes(s, /) -> Buffer:
|
|
77
|
+
if isinstance(s, Buffer):
|
|
78
78
|
return s
|
|
79
79
|
if isinstance(s, int):
|
|
80
80
|
return int_to_bytes(s)
|
|
@@ -88,16 +88,14 @@ def ensure_bytes(s, /) -> bytes | bytearray | memoryview:
|
|
|
88
88
|
|
|
89
89
|
def encode_multipart_data(
|
|
90
90
|
data: Mapping[str, Any],
|
|
91
|
-
files: Mapping[str,
|
|
92
|
-
SupportsRead[bytes] | SupportsRead[bytearray] | SupportsRead[memoryview] |
|
|
93
|
-
Iterable[bytes] | Iterable[bytearray] | Iterable[memoryview]],
|
|
91
|
+
files: Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer]],
|
|
94
92
|
boundary: None | str = None,
|
|
95
|
-
) -> tuple[dict, Iterator[
|
|
93
|
+
) -> tuple[dict, Iterator[Buffer]]:
|
|
96
94
|
if not boundary:
|
|
97
95
|
boundary = uuid4().bytes.hex()
|
|
98
96
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
99
97
|
|
|
100
|
-
def encode_data(data) -> Iterator[
|
|
98
|
+
def encode_data(data) -> Iterator[Buffer]:
|
|
101
99
|
if isinstance(data, Mapping):
|
|
102
100
|
data = ItemsView(data)
|
|
103
101
|
for name, value in data:
|
|
@@ -106,13 +104,13 @@ def encode_multipart_data(
|
|
|
106
104
|
yield ensure_bytes(value)
|
|
107
105
|
yield b"\r\n"
|
|
108
106
|
|
|
109
|
-
def encode_files(files) -> Iterator[
|
|
107
|
+
def encode_files(files) -> Iterator[Buffer]:
|
|
110
108
|
if isinstance(files, Mapping):
|
|
111
109
|
files = ItemsView(files)
|
|
112
110
|
for name, file in files:
|
|
113
111
|
yield boundary_line
|
|
114
112
|
yield b'Content-Disposition: form-data; name="%s"\r\nContent-Type: application/octet-stream\r\n\r\n' % bytes(quote(name), "ascii")
|
|
115
|
-
if isinstance(file,
|
|
113
|
+
if isinstance(file, Buffer):
|
|
116
114
|
yield file
|
|
117
115
|
elif hasattr(file, "read"):
|
|
118
116
|
yield from bio_chunk_iter(file)
|
|
@@ -126,17 +124,14 @@ def encode_multipart_data(
|
|
|
126
124
|
|
|
127
125
|
def encode_multipart_data_async(
|
|
128
126
|
data: Mapping[str, Any],
|
|
129
|
-
files: Mapping[str,
|
|
130
|
-
SupportsRead[bytes] | SupportsRead[bytearray] | SupportsRead[memoryview] |
|
|
131
|
-
Iterable[bytes] | Iterable[bytearray] | Iterable[memoryview] |
|
|
132
|
-
AsyncIterable[bytes] | AsyncIterable[bytearray] | AsyncIterable[memoryview]],
|
|
127
|
+
files: Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer] | AsyncIterable[Buffer]],
|
|
133
128
|
boundary: None | str = None,
|
|
134
|
-
) -> tuple[dict, AsyncIterator[
|
|
129
|
+
) -> tuple[dict, AsyncIterator[Buffer]]:
|
|
135
130
|
if not boundary:
|
|
136
131
|
boundary = uuid4().bytes.hex()
|
|
137
132
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
138
133
|
|
|
139
|
-
async def encode_data(data) -> AsyncIterator[
|
|
134
|
+
async def encode_data(data) -> AsyncIterator[Buffer]:
|
|
140
135
|
if isinstance(data, Mapping):
|
|
141
136
|
data = ItemsView(data)
|
|
142
137
|
for name, value in data:
|
|
@@ -145,13 +140,13 @@ def encode_multipart_data_async(
|
|
|
145
140
|
yield ensure_bytes(value)
|
|
146
141
|
yield b"\r\n"
|
|
147
142
|
|
|
148
|
-
async def encode_files(files) -> AsyncIterator[
|
|
143
|
+
async def encode_files(files) -> AsyncIterator[Buffer]:
|
|
149
144
|
if isinstance(files, Mapping):
|
|
150
145
|
files = ItemsView(files)
|
|
151
146
|
for name, file in files:
|
|
152
147
|
yield boundary_line
|
|
153
148
|
yield b'Content-Disposition: form-data; name="%s"\r\nContent-Type: application/octet-stream\r\n\r\n' % bytes(quote(name), "ascii")
|
|
154
|
-
if isinstance(file,
|
|
149
|
+
if isinstance(file, Buffer):
|
|
155
150
|
yield file
|
|
156
151
|
elif hasattr(file, "read"):
|
|
157
152
|
async for b in bio_chunk_async_iter(file):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python-http_request"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.5.1"
|
|
4
4
|
description = "Python http response utils."
|
|
5
5
|
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -28,7 +28,7 @@ include = [
|
|
|
28
28
|
[tool.poetry.dependencies]
|
|
29
29
|
python = "^3.10"
|
|
30
30
|
python-asynctools = "*"
|
|
31
|
-
python-filewrap = "
|
|
31
|
+
python-filewrap = ">=0.1"
|
|
32
32
|
python-texttools = "*"
|
|
33
33
|
integer_tool = "*"
|
|
34
34
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|