python-http_request 0.0.1__tar.gz → 0.0.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.1 → python_http_request-0.0.2}/PKG-INFO +1 -1
- {python_http_request-0.0.1 → python_http_request-0.0.2}/http_request/__init__.py +23 -11
- {python_http_request-0.0.1 → python_http_request-0.0.2}/pyproject.toml +1 -1
- {python_http_request-0.0.1 → python_http_request-0.0.2}/LICENSE +0 -0
- {python_http_request-0.0.1 → python_http_request-0.0.2}/http_request/py.typed +0 -0
- {python_http_request-0.0.1 → python_http_request-0.0.2}/readme.md +0 -0
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 0,
|
|
6
|
-
__all__ = ["encode_multipart_data", "encode_multipart_data_async"]
|
|
5
|
+
__version__ = (0, 0, 2)
|
|
6
|
+
__all__ = ["SupportsGeturl", "encode_multipart_data", "encode_multipart_data_async"]
|
|
7
7
|
|
|
8
8
|
from itertools import chain
|
|
9
9
|
from collections.abc import AsyncIterable, AsyncIterator, ItemsView, Iterable, Iterator, Mapping
|
|
10
|
-
from typing import Any
|
|
10
|
+
from typing import Any, Protocol, TypeVar
|
|
11
11
|
from urllib.parse import quote
|
|
12
12
|
from uuid import uuid4
|
|
13
13
|
|
|
@@ -16,6 +16,13 @@ from filewrap import bio_chunk_iter, bio_chunk_async_iter, SupportsRead
|
|
|
16
16
|
from integer_tool import int_to_bytes
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
AnyStr = TypeVar("AnyStr", bytes, str, covariant=True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SupportsGeturl(Protocol[AnyStr]):
|
|
23
|
+
def geturl(self) -> AnyStr: ...
|
|
24
|
+
|
|
25
|
+
|
|
19
26
|
def ensure_bytes(s, /) -> bytes | bytearray | memoryview:
|
|
20
27
|
if isinstance(s, (bytes, bytearray, memoryview)):
|
|
21
28
|
return s
|
|
@@ -31,14 +38,16 @@ def ensure_bytes(s, /) -> bytes | bytearray | memoryview:
|
|
|
31
38
|
|
|
32
39
|
def encode_multipart_data(
|
|
33
40
|
data: Mapping[str, Any],
|
|
34
|
-
files: Mapping[str, bytes | bytearray | memoryview |
|
|
41
|
+
files: Mapping[str, bytes | bytearray | memoryview |
|
|
42
|
+
SupportsRead[bytes] | SupportsRead[bytearray] | SupportsRead[memoryview] |
|
|
43
|
+
Iterable[bytes] | Iterable[bytearray] | Iterable[memoryview]],
|
|
35
44
|
boundary: None | str = None,
|
|
36
|
-
) -> tuple[dict, Iterator[bytes]]:
|
|
45
|
+
) -> tuple[dict, Iterator[bytes | bytearray | memoryview]]:
|
|
37
46
|
if not boundary:
|
|
38
47
|
boundary = uuid4().bytes.hex()
|
|
39
48
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
40
49
|
|
|
41
|
-
def encode_data(data) -> Iterator[bytes]:
|
|
50
|
+
def encode_data(data) -> Iterator[bytes | bytearray | memoryview]:
|
|
42
51
|
if isinstance(data, Mapping):
|
|
43
52
|
data = ItemsView(data)
|
|
44
53
|
for name, value in data:
|
|
@@ -47,7 +56,7 @@ def encode_multipart_data(
|
|
|
47
56
|
yield ensure_bytes(value)
|
|
48
57
|
yield b"\r\n"
|
|
49
58
|
|
|
50
|
-
def encode_files(files) -> Iterator[bytes]:
|
|
59
|
+
def encode_files(files) -> Iterator[bytes | bytearray | memoryview]:
|
|
51
60
|
if isinstance(files, Mapping):
|
|
52
61
|
files = ItemsView(files)
|
|
53
62
|
for name, file in files:
|
|
@@ -67,14 +76,17 @@ def encode_multipart_data(
|
|
|
67
76
|
|
|
68
77
|
def encode_multipart_data_async(
|
|
69
78
|
data: Mapping[str, Any],
|
|
70
|
-
files: Mapping[str, bytes | bytearray | memoryview |
|
|
79
|
+
files: Mapping[str, bytes | bytearray | memoryview |
|
|
80
|
+
SupportsRead[bytes] | SupportsRead[bytearray] | SupportsRead[memoryview] |
|
|
81
|
+
Iterable[bytes] | Iterable[bytearray] | Iterable[memoryview] |
|
|
82
|
+
AsyncIterable[bytes] | AsyncIterable[bytearray] | AsyncIterable[memoryview]],
|
|
71
83
|
boundary: None | str = None,
|
|
72
|
-
) -> tuple[dict, AsyncIterator[bytes]]:
|
|
84
|
+
) -> tuple[dict, AsyncIterator[bytes | bytearray | memoryview]]:
|
|
73
85
|
if not boundary:
|
|
74
86
|
boundary = uuid4().bytes.hex()
|
|
75
87
|
headers = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
|
76
88
|
|
|
77
|
-
async def encode_data(data) -> AsyncIterator[bytes]:
|
|
89
|
+
async def encode_data(data) -> AsyncIterator[bytes | bytearray | memoryview]:
|
|
78
90
|
if isinstance(data, Mapping):
|
|
79
91
|
data = ItemsView(data)
|
|
80
92
|
for name, value in data:
|
|
@@ -83,7 +95,7 @@ def encode_multipart_data_async(
|
|
|
83
95
|
yield ensure_bytes(value)
|
|
84
96
|
yield b"\r\n"
|
|
85
97
|
|
|
86
|
-
async def encode_files(files) -> AsyncIterator[bytes]:
|
|
98
|
+
async def encode_files(files) -> AsyncIterator[bytes | bytearray | memoryview]:
|
|
87
99
|
if isinstance(files, Mapping):
|
|
88
100
|
files = ItemsView(files)
|
|
89
101
|
for name, file in files:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|