redc 0.1.0.dev0__cp311-cp311-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 ADDED
@@ -0,0 +1,21 @@
1
+ from .callbacks import StreamCallback
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
+ "utils",
15
+ ]
16
+
17
+ __version__ = "0.1.0.dev0"
18
+ __copyright__ = "Copyright (c) 2025 RedC, AYMENJD"
19
+ __license__ = "MIT License"
20
+
21
+ 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,40 @@
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
+ )