redc 0.1.1.dev0__tar.gz → 0.1.1.dev1__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.
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/CMakeLists.txt +1 -1
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/PKG-INFO +1 -1
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/pyproject.toml +3 -2
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/__init__.py +1 -1
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/client.py +28 -3
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/ext/redc.cpp +7 -3
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/ext/redc.h +3 -0
- redc-0.1.1.dev0/wheelhouse/redc-0.1.1.dev0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl → redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +0 -0
- redc-0.1.1.dev0/wheelhouse/redc-0.1.1.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl → redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +0 -0
- redc-0.1.1.dev0/wheelhouse/redc-0.1.1.dev0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl → redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +0 -0
- redc-0.1.1.dev0/wheelhouse/redc-0.1.1.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl → redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +0 -0
- redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/.clang-format +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/.github/workflows/before-all.sh +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/.github/workflows/build_wheels.yml +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/.gitignore +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/CMake/PreventInSourceBuild.cmake +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/LICENSE +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/README.md +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/assets/images/redc-logo.png +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/callback.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/callbacks.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/codes.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/exceptions/__init__.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/ext/utils/concurrentqueue.h +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/ext/utils/curl_utils.h +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/response.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/utils/__init__.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/utils/headers.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/utils/http.py +0 -0
- {redc-0.1.1.dev0 → redc-0.1.1.dev1}/redc/utils/json_encoder.py +0 -0
@@ -43,7 +43,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
43
43
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
44
44
|
endif()
|
45
45
|
|
46
|
-
nanobind_add_module(redc_ext STABLE_ABI LTO redc/ext/redc.cpp)
|
46
|
+
nanobind_add_module(redc_ext STABLE_ABI FREE_THREADED LTO redc/ext/redc.cpp)
|
47
47
|
|
48
48
|
target_link_libraries(redc_ext PRIVATE CURL::libcurl)
|
49
49
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: redc
|
3
|
-
Version: 0.1.1.
|
3
|
+
Version: 0.1.1.dev1
|
4
4
|
Summary: RedC is a high-performance, asynchronous HTTP client library for Python, built on top of the powerful curl library
|
5
5
|
Keywords: asyncio,http,client,http-client,curl,libcurl
|
6
6
|
Author-Email: AYMEN Mohammed <let.me.code.safe@gmail.com>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
[build-system]
|
2
|
-
requires = ["scikit-build-core >=0.10", "nanobind >=
|
2
|
+
requires = ["scikit-build-core >=0.10", "nanobind >=2.2.0"]
|
3
3
|
build-backend = "scikit_build_core.build"
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "redc"
|
7
|
-
version = "0.1.1.
|
7
|
+
version = "0.1.1.dev1"
|
8
8
|
description = "RedC is a high-performance, asynchronous HTTP client library for Python, built on top of the powerful curl library"
|
9
9
|
readme = "README.md"
|
10
10
|
authors = [{ name = "AYMEN Mohammed", email = "let.me.code.safe@gmail.com" }]
|
@@ -23,6 +23,7 @@ wheel.py-api = "cp312"
|
|
23
23
|
[tool.cibuildwheel]
|
24
24
|
build-verbosity = 1
|
25
25
|
build = "cp39* cp310* cp311* cp312* cp313*"
|
26
|
+
free-threaded-support = true
|
26
27
|
skip = "*musllinux*"
|
27
28
|
archs = ["x86_64"]
|
28
29
|
|
@@ -3,7 +3,10 @@ from urllib.parse import urlencode
|
|
3
3
|
from .callbacks import StreamCallback, ProgressCallback
|
4
4
|
from .redc_ext import RedC
|
5
5
|
from .response import Response
|
6
|
-
from .utils import json_dumps, parse_base_url
|
6
|
+
from .utils import json_dumps, parse_base_url, Headers
|
7
|
+
|
8
|
+
import asyncio
|
9
|
+
import redc
|
7
10
|
|
8
11
|
|
9
12
|
class Client:
|
@@ -77,12 +80,15 @@ class Client:
|
|
77
80
|
self.__base_url = (
|
78
81
|
parse_base_url(base_url) if isinstance(base_url, str) else None
|
79
82
|
)
|
80
|
-
self.__default_headers = headers if isinstance(headers, dict) else {}
|
83
|
+
self.__default_headers = Headers(headers if isinstance(headers, dict) else {})
|
81
84
|
self.__timeout = timeout
|
82
85
|
self.__ca_cert_path = ca_cert_path if isinstance(ca_cert_path, str) else ""
|
83
86
|
self.__json_encoder = json_encoder
|
87
|
+
self.__loop = asyncio.get_event_loop()
|
84
88
|
self.__redc_ext = RedC(buffer_size)
|
85
89
|
|
90
|
+
self.__set_default_headers()
|
91
|
+
|
86
92
|
async def __aenter__(self):
|
87
93
|
return self
|
88
94
|
|
@@ -99,6 +105,12 @@ class Client:
|
|
99
105
|
|
100
106
|
return self.__redc_ext.is_running()
|
101
107
|
|
108
|
+
@property
|
109
|
+
def default_headers(self):
|
110
|
+
"""Returns default headers that are set on all requests"""
|
111
|
+
|
112
|
+
return self.__default_headers
|
113
|
+
|
102
114
|
async def request(
|
103
115
|
self,
|
104
116
|
method: str,
|
@@ -362,6 +374,7 @@ class Client:
|
|
362
374
|
Returns:
|
363
375
|
:class:`redc.Response`
|
364
376
|
"""
|
377
|
+
|
365
378
|
return await self.request(
|
366
379
|
method="HEAD",
|
367
380
|
url=url,
|
@@ -445,6 +458,7 @@ class Client:
|
|
445
458
|
Returns:
|
446
459
|
:class:`redc.Response`
|
447
460
|
"""
|
461
|
+
|
448
462
|
return await self.request(
|
449
463
|
method="POST",
|
450
464
|
url=url,
|
@@ -534,6 +548,7 @@ class Client:
|
|
534
548
|
Returns:
|
535
549
|
:class:`redc.Response`
|
536
550
|
"""
|
551
|
+
|
537
552
|
return await self.request(
|
538
553
|
method="PUT",
|
539
554
|
url=url,
|
@@ -693,6 +708,7 @@ class Client:
|
|
693
708
|
Returns:
|
694
709
|
:class:`redc.Response`
|
695
710
|
"""
|
711
|
+
|
696
712
|
return await self.request(
|
697
713
|
method="DELETE",
|
698
714
|
url=url,
|
@@ -750,6 +766,7 @@ class Client:
|
|
750
766
|
Returns:
|
751
767
|
:class:`redc.Response`
|
752
768
|
"""
|
769
|
+
|
753
770
|
return await self.request(
|
754
771
|
method="OPTIONS",
|
755
772
|
url=url,
|
@@ -768,4 +785,12 @@ class Client:
|
|
768
785
|
This method must be called when the client is no longer needed to avoid memory leaks
|
769
786
|
or unexpected behavior
|
770
787
|
"""
|
771
|
-
|
788
|
+
|
789
|
+
return await self.__loop.run_in_executor(None, self.__redc_ext.close)
|
790
|
+
|
791
|
+
def __set_default_headers(self):
|
792
|
+
if "user-agent" not in self.__default_headers:
|
793
|
+
self.__default_headers["user-agent"] = f"redc/{redc.__version__}"
|
794
|
+
|
795
|
+
if "connection" not in self.__default_headers:
|
796
|
+
self.__default_headers["connection"] = "keep-alive"
|
@@ -73,6 +73,7 @@ py_object RedC::request(const char *method, const char *url, const char *raw_dat
|
|
73
73
|
curl_easy_setopt(easy, CURLOPT_BUFFERSIZE, buffer_size_);
|
74
74
|
curl_easy_setopt(easy, CURLOPT_URL, url);
|
75
75
|
curl_easy_setopt(easy, CURLOPT_CUSTOMREQUEST, method);
|
76
|
+
curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L);
|
76
77
|
|
77
78
|
curl_easy_setopt(easy, CURLOPT_TIMEOUT_MS, timeout_ms);
|
78
79
|
|
@@ -177,10 +178,12 @@ py_object RedC::request(const char *method, const char *url, const char *raw_dat
|
|
177
178
|
|
178
179
|
if (!stream_callback.is_none()) {
|
179
180
|
d.stream_callback = stream_callback;
|
181
|
+
d.has_stream_callback = true;
|
180
182
|
}
|
181
183
|
|
182
184
|
if (!progress_callback.is_none()) {
|
183
185
|
d.progress_callback = progress_callback;
|
186
|
+
d.has_progress_callback = true;
|
184
187
|
|
185
188
|
curl_easy_setopt(easy, CURLOPT_XFERINFODATA, &d);
|
186
189
|
curl_easy_setopt(easy, CURLOPT_NOPROGRESS, 0L);
|
@@ -316,9 +319,10 @@ size_t RedC::header_callback(char *buffer, size_t size, size_t nitems, Data *cli
|
|
316
319
|
|
317
320
|
size_t RedC::progress_callback(Data *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal,
|
318
321
|
curl_off_t ulnow) {
|
319
|
-
if (
|
322
|
+
if (clientp->has_progress_callback) {
|
320
323
|
try {
|
321
|
-
acq_gil
|
324
|
+
acq_gil
|
325
|
+
gil; //TODO: this sometimes hangs on exit, which lead to other functions to block such as curl_multi_perform and worker_loop never exit
|
322
326
|
clientp->progress_callback(dltotal, dlnow, ultotal, ulnow);
|
323
327
|
} catch (const std::exception &e) {
|
324
328
|
std::cerr << "Error in progress_callback: " << e.what() << std::endl;
|
@@ -331,7 +335,7 @@ size_t RedC::progress_callback(Data *clientp, curl_off_t dltotal, curl_off_t dln
|
|
331
335
|
size_t RedC::write_callback(char *data, size_t size, size_t nmemb, Data *clientp) {
|
332
336
|
size_t total_size = size * nmemb;
|
333
337
|
|
334
|
-
if (
|
338
|
+
if (clientp->has_stream_callback) {
|
335
339
|
try {
|
336
340
|
acq_gil gil;
|
337
341
|
clientp->stream_callback(py_bytes(data, total_size), total_size);
|
@@ -38,6 +38,9 @@ struct Data {
|
|
38
38
|
py_object stream_callback{nb::none()};
|
39
39
|
py_object progress_callback{nb::none()};
|
40
40
|
|
41
|
+
bool has_stream_callback{false};
|
42
|
+
bool has_progress_callback{false};
|
43
|
+
|
41
44
|
std::vector<char> headers;
|
42
45
|
CurlSlist request_headers;
|
43
46
|
CurlMime curl_mime_;
|
index 749bb4e..41ad850 100644
|
|
Binary file
|
index 96ed50c..a088e2c 100644
|
|
Binary file
|
index d3a6d16..84f9bd4 100644
|
|
Binary file
|
index d29ee0d..631cec1 100644
|
|
Binary file
|
redc-0.1.1.dev1/wheelhouse/redc-0.1.1.dev1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
ADDED
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|