python-http_request 0.0.5__tar.gz → 0.0.5.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.0.5 → python_http_request-0.0.5.2}/PKG-INFO +1 -1
- {python_http_request-0.0.5 → python_http_request-0.0.5.2}/http_request/__init__.py +14 -6
- {python_http_request-0.0.5 → python_http_request-0.0.5.2}/pyproject.toml +1 -1
- {python_http_request-0.0.5 → python_http_request-0.0.5.2}/LICENSE +0 -0
- {python_http_request-0.0.5 → python_http_request-0.0.5.2}/http_request/py.typed +0 -0
- {python_http_request-0.0.5 → python_http_request-0.0.5.2}/readme.md +0 -0
|
@@ -87,8 +87,8 @@ def ensure_bytes(s, /) -> Buffer:
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
def encode_multipart_data(
|
|
90
|
-
data: Mapping[str, Any],
|
|
91
|
-
files: Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer]],
|
|
90
|
+
data: None | Mapping[str, Any] = None,
|
|
91
|
+
files: None | Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer]] = None,
|
|
92
92
|
boundary: None | str = None,
|
|
93
93
|
) -> tuple[dict, Iterator[Buffer]]:
|
|
94
94
|
if not boundary:
|
|
@@ -96,6 +96,8 @@ def encode_multipart_data(
|
|
|
96
96
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
97
97
|
|
|
98
98
|
def encode_data(data) -> Iterator[Buffer]:
|
|
99
|
+
if not data:
|
|
100
|
+
return
|
|
99
101
|
if isinstance(data, Mapping):
|
|
100
102
|
data = ItemsView(data)
|
|
101
103
|
for name, value in data:
|
|
@@ -105,12 +107,14 @@ def encode_multipart_data(
|
|
|
105
107
|
yield b"\r\n"
|
|
106
108
|
|
|
107
109
|
def encode_files(files) -> Iterator[Buffer]:
|
|
110
|
+
if not data:
|
|
111
|
+
return
|
|
108
112
|
if isinstance(files, Mapping):
|
|
109
113
|
files = ItemsView(files)
|
|
110
114
|
for name, file in files:
|
|
111
115
|
yield boundary_line
|
|
112
116
|
yield b'Content-Disposition: form-data; name="%s"\r\nContent-Type: application/octet-stream\r\n\r\n' % bytes(quote(name), "ascii")
|
|
113
|
-
if isinstance(file,
|
|
117
|
+
if isinstance(file, Buffer):
|
|
114
118
|
yield file
|
|
115
119
|
elif hasattr(file, "read"):
|
|
116
120
|
yield from bio_chunk_iter(file)
|
|
@@ -123,8 +127,8 @@ def encode_multipart_data(
|
|
|
123
127
|
|
|
124
128
|
|
|
125
129
|
def encode_multipart_data_async(
|
|
126
|
-
data: Mapping[str, Any],
|
|
127
|
-
files: Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer] | AsyncIterable[Buffer]],
|
|
130
|
+
data: None | Mapping[str, Any] = None,
|
|
131
|
+
files: None | Mapping[str, Buffer | SupportsRead[Buffer] | Iterable[Buffer] | AsyncIterable[Buffer]] = None,
|
|
128
132
|
boundary: None | str = None,
|
|
129
133
|
) -> tuple[dict, AsyncIterator[Buffer]]:
|
|
130
134
|
if not boundary:
|
|
@@ -132,6 +136,8 @@ def encode_multipart_data_async(
|
|
|
132
136
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
133
137
|
|
|
134
138
|
async def encode_data(data) -> AsyncIterator[Buffer]:
|
|
139
|
+
if not data:
|
|
140
|
+
return
|
|
135
141
|
if isinstance(data, Mapping):
|
|
136
142
|
data = ItemsView(data)
|
|
137
143
|
for name, value in data:
|
|
@@ -141,12 +147,14 @@ def encode_multipart_data_async(
|
|
|
141
147
|
yield b"\r\n"
|
|
142
148
|
|
|
143
149
|
async def encode_files(files) -> AsyncIterator[Buffer]:
|
|
150
|
+
if not data:
|
|
151
|
+
return
|
|
144
152
|
if isinstance(files, Mapping):
|
|
145
153
|
files = ItemsView(files)
|
|
146
154
|
for name, file in files:
|
|
147
155
|
yield boundary_line
|
|
148
156
|
yield b'Content-Disposition: form-data; name="%s"\r\nContent-Type: application/octet-stream\r\n\r\n' % bytes(quote(name), "ascii")
|
|
149
|
-
if isinstance(file,
|
|
157
|
+
if isinstance(file, Buffer):
|
|
150
158
|
yield file
|
|
151
159
|
elif hasattr(file, "read"):
|
|
152
160
|
async for b in bio_chunk_async_iter(file):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|