rusty-req 0.1.4__tar.gz → 0.1.6__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.
Potentially problematic release.
This version of rusty-req might be problematic. Click here for more details.
- rusty_req-0.1.6/.github/workflows/build.yml +42 -0
- {rusty_req-0.1.4 → rusty_req-0.1.6}/.gitignore +1 -1
- {rusty_req-0.1.4 → rusty_req-0.1.6}/Cargo.lock +86 -1
- rusty_req-0.1.6/Cargo.toml +26 -0
- {rusty_req-0.1.4 → rusty_req-0.1.6}/PKG-INFO +7 -4
- {rusty_req-0.1.4 → rusty_req-0.1.6}/README.md +6 -3
- {rusty_req-0.1.4 → rusty_req-0.1.6}/pyproject.toml +11 -15
- {rusty_req-0.1.4 → rusty_req-0.1.6}/src/lib.rs +55 -4
- rusty_req-0.1.6/sync_version.py +17 -0
- rusty_req-0.1.6/version.txt +1 -0
- rusty_req-0.1.4/.idea/.gitignore +0 -8
- rusty_req-0.1.4/.idea/modules.xml +0 -8
- rusty_req-0.1.4/.idea/py_req_ext.iml +0 -11
- rusty_req-0.1.4/.idea/vcs.xml +0 -6
- rusty_req-0.1.4/Cargo.toml +0 -14
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Build and Publish Rust Python Extension
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main # 代码提交到 main 分支触发
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main # PR 目标分支为 main 时触发
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build-and-publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Setup Rust
|
|
18
|
+
uses: actions-rs/toolchain@v1
|
|
19
|
+
with:
|
|
20
|
+
profile: minimal
|
|
21
|
+
toolchain: stable
|
|
22
|
+
override: true
|
|
23
|
+
|
|
24
|
+
- name: Setup Python
|
|
25
|
+
uses: actions/setup-python@v4
|
|
26
|
+
with:
|
|
27
|
+
python-version: 3.12.11
|
|
28
|
+
|
|
29
|
+
- name: Upgrade pip
|
|
30
|
+
run: pip install --upgrade pip
|
|
31
|
+
|
|
32
|
+
- name: Install maturin
|
|
33
|
+
run: pip install maturin
|
|
34
|
+
|
|
35
|
+
- name: Build Rust Python extension
|
|
36
|
+
run: maturin build --release
|
|
37
|
+
|
|
38
|
+
- name: Publish to PyPI
|
|
39
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
40
|
+
env:
|
|
41
|
+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
42
|
+
run: maturin publish --skip-existing
|
|
@@ -18,4 +18,4 @@ target
|
|
|
18
18
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
19
19
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
20
20
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
21
|
-
.idea
|
|
21
|
+
.idea
|
|
@@ -17,6 +17,21 @@ version = "2.0.1"
|
|
|
17
17
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
18
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
|
19
19
|
|
|
20
|
+
[[package]]
|
|
21
|
+
name = "alloc-no-stdlib"
|
|
22
|
+
version = "2.0.4"
|
|
23
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
24
|
+
checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "alloc-stdlib"
|
|
28
|
+
version = "0.2.2"
|
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
30
|
+
checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
|
|
31
|
+
dependencies = [
|
|
32
|
+
"alloc-no-stdlib",
|
|
33
|
+
]
|
|
34
|
+
|
|
20
35
|
[[package]]
|
|
21
36
|
name = "android-tzdata"
|
|
22
37
|
version = "0.1.1"
|
|
@@ -32,6 +47,20 @@ dependencies = [
|
|
|
32
47
|
"libc",
|
|
33
48
|
]
|
|
34
49
|
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "async-compression"
|
|
52
|
+
version = "0.4.25"
|
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
54
|
+
checksum = "40f6024f3f856663b45fd0c9b6f2024034a702f453549449e0d84a305900dad4"
|
|
55
|
+
dependencies = [
|
|
56
|
+
"brotli",
|
|
57
|
+
"flate2",
|
|
58
|
+
"futures-core",
|
|
59
|
+
"memchr",
|
|
60
|
+
"pin-project-lite",
|
|
61
|
+
"tokio",
|
|
62
|
+
]
|
|
63
|
+
|
|
35
64
|
[[package]]
|
|
36
65
|
name = "autocfg"
|
|
37
66
|
version = "1.5.0"
|
|
@@ -71,6 +100,27 @@ version = "2.9.1"
|
|
|
71
100
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
72
101
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
|
73
102
|
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "brotli"
|
|
105
|
+
version = "8.0.1"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "9991eea70ea4f293524138648e41ee89b0b2b12ddef3b255effa43c8056e0e0d"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"alloc-no-stdlib",
|
|
110
|
+
"alloc-stdlib",
|
|
111
|
+
"brotli-decompressor",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
[[package]]
|
|
115
|
+
name = "brotli-decompressor"
|
|
116
|
+
version = "5.0.0"
|
|
117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
118
|
+
checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03"
|
|
119
|
+
dependencies = [
|
|
120
|
+
"alloc-no-stdlib",
|
|
121
|
+
"alloc-stdlib",
|
|
122
|
+
]
|
|
123
|
+
|
|
74
124
|
[[package]]
|
|
75
125
|
name = "bumpalo"
|
|
76
126
|
version = "3.19.0"
|
|
@@ -128,6 +178,15 @@ version = "0.8.7"
|
|
|
128
178
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
129
179
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
|
130
180
|
|
|
181
|
+
[[package]]
|
|
182
|
+
name = "crc32fast"
|
|
183
|
+
version = "1.4.2"
|
|
184
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
185
|
+
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
|
186
|
+
dependencies = [
|
|
187
|
+
"cfg-if",
|
|
188
|
+
]
|
|
189
|
+
|
|
131
190
|
[[package]]
|
|
132
191
|
name = "displaydoc"
|
|
133
192
|
version = "0.2.5"
|
|
@@ -170,6 +229,16 @@ version = "2.3.0"
|
|
|
170
229
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
171
230
|
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
|
172
231
|
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "flate2"
|
|
234
|
+
version = "1.1.2"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
|
|
237
|
+
dependencies = [
|
|
238
|
+
"crc32fast",
|
|
239
|
+
"miniz_oxide",
|
|
240
|
+
]
|
|
241
|
+
|
|
173
242
|
[[package]]
|
|
174
243
|
name = "fnv"
|
|
175
244
|
version = "1.0.7"
|
|
@@ -926,6 +995,7 @@ version = "0.11.27"
|
|
|
926
995
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
927
996
|
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
|
|
928
997
|
dependencies = [
|
|
998
|
+
"async-compression",
|
|
929
999
|
"base64",
|
|
930
1000
|
"bytes",
|
|
931
1001
|
"encoding_rs",
|
|
@@ -952,10 +1022,12 @@ dependencies = [
|
|
|
952
1022
|
"system-configuration",
|
|
953
1023
|
"tokio",
|
|
954
1024
|
"tokio-native-tls",
|
|
1025
|
+
"tokio-util",
|
|
955
1026
|
"tower-service",
|
|
956
1027
|
"url",
|
|
957
1028
|
"wasm-bindgen",
|
|
958
1029
|
"wasm-bindgen-futures",
|
|
1030
|
+
"wasm-streams",
|
|
959
1031
|
"web-sys",
|
|
960
1032
|
"winreg",
|
|
961
1033
|
]
|
|
@@ -996,7 +1068,7 @@ checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
|
|
|
996
1068
|
|
|
997
1069
|
[[package]]
|
|
998
1070
|
name = "rusty-req"
|
|
999
|
-
version = "0.1.
|
|
1071
|
+
version = "0.1.6"
|
|
1000
1072
|
dependencies = [
|
|
1001
1073
|
"chrono",
|
|
1002
1074
|
"futures",
|
|
@@ -1432,6 +1504,19 @@ dependencies = [
|
|
|
1432
1504
|
"unicode-ident",
|
|
1433
1505
|
]
|
|
1434
1506
|
|
|
1507
|
+
[[package]]
|
|
1508
|
+
name = "wasm-streams"
|
|
1509
|
+
version = "0.4.2"
|
|
1510
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1511
|
+
checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65"
|
|
1512
|
+
dependencies = [
|
|
1513
|
+
"futures-util",
|
|
1514
|
+
"js-sys",
|
|
1515
|
+
"wasm-bindgen",
|
|
1516
|
+
"wasm-bindgen-futures",
|
|
1517
|
+
"web-sys",
|
|
1518
|
+
]
|
|
1519
|
+
|
|
1435
1520
|
[[package]]
|
|
1436
1521
|
name = "web-sys"
|
|
1437
1522
|
version = "0.3.77"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "rusty-req"
|
|
3
|
+
version = "0.1.6"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
serde_json = "1.0"
|
|
8
|
+
chrono = "0.4"
|
|
9
|
+
futures = "0.3"
|
|
10
|
+
once_cell = "1.18"
|
|
11
|
+
|
|
12
|
+
[dependencies.pyo3]
|
|
13
|
+
version = "0.20"
|
|
14
|
+
features = [ "extension-module",]
|
|
15
|
+
|
|
16
|
+
[dependencies.pyo3-asyncio]
|
|
17
|
+
version = "0.20"
|
|
18
|
+
features = [ "tokio-runtime",]
|
|
19
|
+
|
|
20
|
+
[dependencies.tokio]
|
|
21
|
+
version = "1.0"
|
|
22
|
+
features = [ "full",]
|
|
23
|
+
|
|
24
|
+
[dependencies.reqwest]
|
|
25
|
+
version = "0.11"
|
|
26
|
+
features = [ "json", "brotli", "gzip", "deflate", "stream",]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rusty-req
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Classifier: Programming Language :: Python
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: Programming Language :: Rust
|
|
@@ -18,6 +18,7 @@ Project-URL: Documentation, https://github.com/KAY53N/rusty-req#readme
|
|
|
18
18
|
|
|
19
19
|
# rusty-req
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
基于 Rust + Python 的高性能异步请求库,适用于需要批量发送 HTTP 请求的场景。通过 Rust 实现并发请求逻辑,并通过 [maturin](https://github.com/PyO3/maturin) 封装为 Python 模块,兼具性能与易用性。
|
|
22
23
|
|
|
23
24
|
## 🔧 安装
|
|
@@ -46,11 +47,11 @@ pip install target/wheels/rusty_req-*.whl
|
|
|
46
47
|
```python
|
|
47
48
|
import asyncio
|
|
48
49
|
import time
|
|
49
|
-
|
|
50
|
+
import rusty_req
|
|
50
51
|
|
|
51
52
|
async def main():
|
|
52
53
|
requests = [
|
|
53
|
-
RequestItem(
|
|
54
|
+
rusty_req.RequestItem(
|
|
54
55
|
url="https://httpbin.org/headers",
|
|
55
56
|
method="GET",
|
|
56
57
|
params=None,
|
|
@@ -66,7 +67,9 @@ async def main():
|
|
|
66
67
|
]
|
|
67
68
|
|
|
68
69
|
start = time.perf_counter()
|
|
69
|
-
|
|
70
|
+
|
|
71
|
+
rusty_req.set_debug(False)
|
|
72
|
+
responses = await rusty_req.fetch_requests(requests, total_timeout=5.0)
|
|
70
73
|
duration = time.perf_counter() - start
|
|
71
74
|
|
|
72
75
|
success = sum(1 for r in responses if not r["error"])
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# rusty-req
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
基于 Rust + Python 的高性能异步请求库,适用于需要批量发送 HTTP 请求的场景。通过 Rust 实现并发请求逻辑,并通过 [maturin](https://github.com/PyO3/maturin) 封装为 Python 模块,兼具性能与易用性。
|
|
4
5
|
|
|
5
6
|
## 🔧 安装
|
|
@@ -28,11 +29,11 @@ pip install target/wheels/rusty_req-*.whl
|
|
|
28
29
|
```python
|
|
29
30
|
import asyncio
|
|
30
31
|
import time
|
|
31
|
-
|
|
32
|
+
import rusty_req
|
|
32
33
|
|
|
33
34
|
async def main():
|
|
34
35
|
requests = [
|
|
35
|
-
RequestItem(
|
|
36
|
+
rusty_req.RequestItem(
|
|
36
37
|
url="https://httpbin.org/headers",
|
|
37
38
|
method="GET",
|
|
38
39
|
params=None,
|
|
@@ -48,7 +49,9 @@ async def main():
|
|
|
48
49
|
]
|
|
49
50
|
|
|
50
51
|
start = time.perf_counter()
|
|
51
|
-
|
|
52
|
+
|
|
53
|
+
rusty_req.set_debug(False)
|
|
54
|
+
responses = await rusty_req.fetch_requests(requests, total_timeout=5.0)
|
|
52
55
|
duration = time.perf_counter() - start
|
|
53
56
|
|
|
54
57
|
success = sum(1 for r in responses if not r["error"])
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rusty-req"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.6"
|
|
4
4
|
edition = "2021"
|
|
5
|
-
authors = ["kaysen <kaysen820@gmail.com>"]
|
|
5
|
+
authors = [ "kaysen <kaysen820@gmail.com>",]
|
|
6
6
|
description = "High-performance async HTTP client built with Rust for Python."
|
|
7
7
|
license = "MIT"
|
|
8
8
|
homepage = "https://github.com/KAY53N/rusty-req"
|
|
@@ -11,30 +11,26 @@ documentation = "https://github.com/KAY53N/rusty-req#readme"
|
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
|
|
13
13
|
[build-system]
|
|
14
|
-
requires = ["maturin>=1.4,<2.0"]
|
|
14
|
+
requires = [ "maturin>=1.4,<2.0",]
|
|
15
15
|
build-backend = "maturin"
|
|
16
16
|
|
|
17
17
|
[project]
|
|
18
18
|
name = "rusty-req"
|
|
19
|
-
version = "0.1.
|
|
19
|
+
version = "0.1.6"
|
|
20
20
|
description = "High-performance async HTTP client built with Rust for Python."
|
|
21
21
|
readme = "README.md"
|
|
22
|
-
authors = [{ name = "KAY53N", email = "kaysen820@gmail.com" }]
|
|
23
22
|
license = "MIT"
|
|
24
23
|
requires-python = ">=3.7"
|
|
25
|
-
classifiers = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"License :: OSI Approved :: MIT License",
|
|
30
|
-
"Operating System :: OS Independent",
|
|
31
|
-
]
|
|
24
|
+
classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Rust", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
|
|
25
|
+
[[project.authors]]
|
|
26
|
+
name = "KAY53N"
|
|
27
|
+
email = "kaysen820@gmail.com"
|
|
32
28
|
|
|
33
29
|
[project.urls]
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
Homepage = "https://github.com/KAY53N/rusty-req"
|
|
31
|
+
Repository = "https://github.com/KAY53N/rusty-req"
|
|
36
32
|
"Bug Tracker" = "https://github.com/KAY53N/rusty-req/issues"
|
|
37
|
-
|
|
33
|
+
Documentation = "https://github.com/KAY53N/rusty-req#readme"
|
|
38
34
|
|
|
39
35
|
[tool.maturin]
|
|
40
36
|
bindings = "pyo3"
|
|
@@ -1,25 +1,69 @@
|
|
|
1
1
|
#![allow(non_local_definitions)]
|
|
2
|
-
|
|
3
|
-
use pyo3::
|
|
2
|
+
// PyO3 宏和类型
|
|
3
|
+
use pyo3::{pyclass, pymethods, pyfunction, pymodule};
|
|
4
|
+
use pyo3::{PyResult, Python, PyAny, Py, wrap_pyfunction};
|
|
5
|
+
use pyo3::types::{PyDict, PyList, PyModule};
|
|
6
|
+
use pyo3::IntoPy;
|
|
7
|
+
|
|
8
|
+
// 其他库
|
|
4
9
|
use std::collections::HashMap;
|
|
5
|
-
use reqwest::Client;
|
|
10
|
+
use reqwest::{Client, Request, StatusCode};
|
|
6
11
|
use std::time::{Duration, SystemTime};
|
|
7
12
|
use futures::future::join_all;
|
|
8
13
|
use serde_json::Value;
|
|
9
14
|
use chrono::{DateTime, Local};
|
|
10
15
|
use once_cell::sync::Lazy;
|
|
11
16
|
use tokio::sync::Mutex;
|
|
17
|
+
use std::sync::atomic::{AtomicBool, Ordering};
|
|
12
18
|
use reqwest::header::{HeaderMap, HeaderName, HeaderValue, ACCEPT_ENCODING, CONNECTION};
|
|
13
19
|
|
|
20
|
+
static DEBUG_MODE: AtomicBool = AtomicBool::new(false);
|
|
14
21
|
|
|
15
22
|
// 全局共享的HTTP客户端
|
|
16
23
|
static GLOBAL_CLIENT: Lazy<Mutex<Client>> = Lazy::new(|| {
|
|
17
24
|
Mutex::new(Client::builder()
|
|
18
25
|
.timeout(Duration::from_secs(30))
|
|
26
|
+
.gzip(true) // 开启 gzip 自动解压
|
|
27
|
+
.brotli(true) // 开启 brotli 自动解压
|
|
28
|
+
.deflate(true) // 开启 deflate 自动解压
|
|
19
29
|
.build()
|
|
20
30
|
.expect("Failed to create HTTP client"))
|
|
21
31
|
});
|
|
22
32
|
|
|
33
|
+
#[pyfunction]
|
|
34
|
+
fn set_debug(enabled: bool) {
|
|
35
|
+
DEBUG_MODE.store(enabled, Ordering::Relaxed);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
pub fn is_debug() -> bool {
|
|
39
|
+
DEBUG_MODE.load(Ordering::Relaxed)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn debug_log(
|
|
43
|
+
tag: &str,
|
|
44
|
+
request: &Request,
|
|
45
|
+
status: StatusCode,
|
|
46
|
+
headers: &HeaderMap,
|
|
47
|
+
body: &str,
|
|
48
|
+
) {
|
|
49
|
+
if !is_debug() {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
println!("\n================== [DEBUG: {}] ==================", tag);
|
|
54
|
+
println!("Request Method : {}", request.method());
|
|
55
|
+
println!("Request URL : {}", request.url());
|
|
56
|
+
println!("--------------------------------------------------");
|
|
57
|
+
println!("Response Status: {}", status);
|
|
58
|
+
println!("Response Headers:");
|
|
59
|
+
for (key, value) in headers.iter() {
|
|
60
|
+
println!(" {}: {:?}", key, value);
|
|
61
|
+
}
|
|
62
|
+
println!("--------------------------------------------------");
|
|
63
|
+
println!("Response Body:\n{}", body);
|
|
64
|
+
println!("==================================================\n");
|
|
65
|
+
}
|
|
66
|
+
|
|
23
67
|
#[pyclass]
|
|
24
68
|
#[derive(Clone)]
|
|
25
69
|
pub struct RequestItem {
|
|
@@ -145,10 +189,16 @@ fn fetch_requests<'py>(
|
|
|
145
189
|
});
|
|
146
190
|
|
|
147
191
|
// 发起请求,使用单个请求超时控制
|
|
148
|
-
let timeout = Duration::from_secs_f64(req.timeout.unwrap_or(
|
|
192
|
+
let timeout = Duration::from_secs_f64(req.timeout.unwrap_or(3.0).max(3.0));
|
|
193
|
+
let tag = req.tag.clone().unwrap_or_else(|| "no-tag".to_string());
|
|
194
|
+
let request_to_send = builder.try_clone().unwrap().build().unwrap();
|
|
149
195
|
match tokio::time::timeout(timeout, builder.send()).await {
|
|
150
196
|
Ok(Ok(res)) => {
|
|
197
|
+
let status = res.status();
|
|
198
|
+
let headers = res.headers().clone(); // 必须 clone,HeaderMap 实现了 Clone
|
|
199
|
+
|
|
151
200
|
if let Ok(text) = res.text().await {
|
|
201
|
+
debug_log(&tag, &request_to_send, status, &headers, &text);
|
|
152
202
|
result.insert("response".to_string(), text);
|
|
153
203
|
}
|
|
154
204
|
},
|
|
@@ -237,5 +287,6 @@ fn format_datetime(time: SystemTime) -> String {
|
|
|
237
287
|
fn rusty_req(_py: Python, m: &PyModule) -> PyResult<()> {
|
|
238
288
|
m.add_class::<RequestItem>()?;
|
|
239
289
|
m.add_function(wrap_pyfunction!(fetch_requests, m)?)?;
|
|
290
|
+
m.add_function(wrap_pyfunction!(set_debug, m)?)?;
|
|
240
291
|
Ok(())
|
|
241
292
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import toml
|
|
2
|
+
|
|
3
|
+
# 读取版本号文件
|
|
4
|
+
with open("version.txt", "r") as f:
|
|
5
|
+
version = f.read().strip()
|
|
6
|
+
|
|
7
|
+
# 更新 Cargo.toml
|
|
8
|
+
cargo = toml.load("Cargo.toml")
|
|
9
|
+
cargo['package']['version'] = version
|
|
10
|
+
with open("Cargo.toml", "w") as f:
|
|
11
|
+
toml.dump(cargo, f)
|
|
12
|
+
|
|
13
|
+
# 更新 pyproject.toml
|
|
14
|
+
pyproject = toml.load("pyproject.toml")
|
|
15
|
+
pyproject['package']['version'] = version # 这里改为访问 package
|
|
16
|
+
with open("pyproject.toml", "w") as f:
|
|
17
|
+
toml.dump(pyproject, f)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.6
|
rusty_req-0.1.4/.idea/.gitignore
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/py_req_ext.iml" filepath="$PROJECT_DIR$/.idea/py_req_ext.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="EMPTY_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
7
|
-
</content>
|
|
8
|
-
<orderEntry type="inheritedJdk" />
|
|
9
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
-
</component>
|
|
11
|
-
</module>
|
rusty_req-0.1.4/.idea/vcs.xml
DELETED
rusty_req-0.1.4/Cargo.toml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "rusty-req"
|
|
3
|
-
version = "0.1.4"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
pyo3 = { version = "0.20", features = ["extension-module"] }
|
|
8
|
-
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
|
|
9
|
-
tokio = { version = "1.0", features = ["full"] }
|
|
10
|
-
reqwest = { version = "0.11", features = ["json"] }
|
|
11
|
-
serde_json = "1.0"
|
|
12
|
-
chrono = "0.4"
|
|
13
|
-
futures = "0.3"
|
|
14
|
-
once_cell = "1.18"
|