redc 0.1.1.dev1__cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
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.
- redc/__init__.py +22 -0
- redc/callback.py +19 -0
- redc/callbacks.py +81 -0
- redc/client.py +796 -0
- redc/codes.py +151 -0
- redc/exceptions/__init__.py +22 -0
- redc/ext/redc.cpp +362 -0
- redc/ext/redc.h +91 -0
- redc/ext/utils/concurrentqueue.h +3747 -0
- redc/ext/utils/curl_utils.h +84 -0
- redc/redc_ext.cpython-313t-x86_64-linux-gnu.so +0 -0
- redc/response.py +68 -0
- redc/utils/__init__.py +5 -0
- redc/utils/headers.py +60 -0
- redc/utils/http.py +12 -0
- redc/utils/json_encoder.py +17 -0
- redc-0.1.1.dev1.dist-info/METADATA +64 -0
- redc-0.1.1.dev1.dist-info/RECORD +27 -0
- redc-0.1.1.dev1.dist-info/WHEEL +6 -0
- redc-0.1.1.dev1.dist-info/licenses/LICENSE +21 -0
- redc.libs/libcrypto-cff6b41d.so.3 +0 -0
- redc.libs/libcurl-bf2af365.so.4.8.0 +0 -0
- redc.libs/libicudata-cb3ba60c.so.50.2 +0 -0
- redc.libs/libicuuc-1796a535.so.50.2 +0 -0
- redc.libs/libnghttp2-cc579893.so.14.17.0 +0 -0
- redc.libs/libpsl-9527e555.so.0.2.4 +0 -0
- redc.libs/libssl-ebec6e5c.so.3 +0 -0
redc/__init__.py
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
from .callbacks import StreamCallback, ProgressCallback
|
2
|
+
from .client import Client
|
3
|
+
from .codes import HTTPStatus
|
4
|
+
from .exceptions import HTTPError
|
5
|
+
from .response import Response
|
6
|
+
from . import utils
|
7
|
+
|
8
|
+
__all__ = [
|
9
|
+
"Client",
|
10
|
+
"Response",
|
11
|
+
"HTTPError",
|
12
|
+
"HTTPStatus",
|
13
|
+
"StreamCallback",
|
14
|
+
"ProgressCallback",
|
15
|
+
"utils",
|
16
|
+
]
|
17
|
+
|
18
|
+
__version__ = "0.1.1.dev1"
|
19
|
+
__copyright__ = "Copyright (c) 2025 RedC, AYMENJD"
|
20
|
+
__license__ = "MIT License"
|
21
|
+
|
22
|
+
VERSION = __version__
|
redc/callback.py
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import inspect
|
2
|
+
from typing import Callable
|
3
|
+
|
4
|
+
|
5
|
+
class Callback:
|
6
|
+
def __init__(self, callback: Callable[[bytes, int], None]):
|
7
|
+
self.callback = callback
|
8
|
+
self._validate_callback()
|
9
|
+
|
10
|
+
def _validate_callback(self):
|
11
|
+
signature = inspect.signature(self.callback)
|
12
|
+
|
13
|
+
parameters = signature.parameters
|
14
|
+
num_parameters = len(parameters)
|
15
|
+
|
16
|
+
if num_parameters != 2:
|
17
|
+
raise TypeError(
|
18
|
+
f"Callback function must accept two arguments only callback(data: bytes, total_size: int), but it accepts {num_parameters}."
|
19
|
+
)
|
redc/callbacks.py
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
import inspect
|
2
|
+
from typing import Callable
|
3
|
+
|
4
|
+
|
5
|
+
class StreamCallback:
|
6
|
+
"""A class for creating a stream callback"""
|
7
|
+
|
8
|
+
def __init__(self, callback: Callable[[bytes, int], None]):
|
9
|
+
"""A callback handler for streaming data
|
10
|
+
|
11
|
+
Example:
|
12
|
+
.. code-block:: python
|
13
|
+
|
14
|
+
>>> def callback(data: bytes, data_size: int):
|
15
|
+
... print(f"Received {len(data)}")
|
16
|
+
>>> stream_callback = StreamCallback(callback)
|
17
|
+
>>> client.get("https://example.com/", stream_callback=stream_callback)
|
18
|
+
|
19
|
+
Parameters:
|
20
|
+
callback (``Callable[[bytes, int], None]``):
|
21
|
+
A function that accepts two arguments: data (``bytes``) and data_size (``int``)
|
22
|
+
The function cannot be asynchronous
|
23
|
+
"""
|
24
|
+
|
25
|
+
self.callback = callback
|
26
|
+
self._validate_callback()
|
27
|
+
|
28
|
+
def _validate_callback(self):
|
29
|
+
if inspect.iscoroutinefunction(self.callback):
|
30
|
+
raise TypeError("Callback function cannot be asynchronous")
|
31
|
+
|
32
|
+
signature = inspect.signature(self.callback)
|
33
|
+
|
34
|
+
parameters = signature.parameters
|
35
|
+
num_parameters = len(parameters)
|
36
|
+
|
37
|
+
if num_parameters != 2:
|
38
|
+
raise TypeError(
|
39
|
+
f"Callback function must accept two arguments only callback(data: bytes, data_size: int) but it accepts {num_parameters}."
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
class ProgressCallback:
|
44
|
+
"""A class for creating a progress callback"""
|
45
|
+
|
46
|
+
def __init__(self, callback: Callable[[int, int, int, int], None]):
|
47
|
+
"""A callback handler for progress updates
|
48
|
+
|
49
|
+
Example:
|
50
|
+
.. code-block:: python
|
51
|
+
|
52
|
+
>>> def callback(dltotal: int, dlnow: int, ultotal: int, ulnow: int):
|
53
|
+
... print(f"Downloaded {dlnow}/{dltotal}, Uploaded {ulnow}/{ultotal}")
|
54
|
+
>>> progress_callback = ProgressCallback(callback)
|
55
|
+
>>> client.get("https://example.com/", progress_callback=progress_callback)
|
56
|
+
|
57
|
+
Parameters:
|
58
|
+
callback (``Callable[[int, int, int, int], None]``):
|
59
|
+
A function that accepts four arguments:
|
60
|
+
- dltotal (``int``): Total bytes expected to be downloaded
|
61
|
+
- dlnow (``int``): Bytes downloaded so far
|
62
|
+
- ultotal (``int``): Total bytes expected to be uploaded
|
63
|
+
- ulnow (``int``): Bytes uploaded so far
|
64
|
+
The function cannot be asynchronous.
|
65
|
+
"""
|
66
|
+
|
67
|
+
self.callback = callback
|
68
|
+
self._validate_callback()
|
69
|
+
|
70
|
+
def _validate_callback(self):
|
71
|
+
if inspect.iscoroutinefunction(self.callback):
|
72
|
+
raise TypeError("Callback function cannot be asynchronous")
|
73
|
+
|
74
|
+
signature = inspect.signature(self.callback)
|
75
|
+
parameters = signature.parameters
|
76
|
+
num_parameters = len(parameters)
|
77
|
+
|
78
|
+
if num_parameters != 4:
|
79
|
+
raise TypeError(
|
80
|
+
f"Callback function must accept exactly four arguments (dltotal: int, dlnow: int, ultotal: int, ulnow: int) but it accepts {num_parameters}."
|
81
|
+
)
|