bencode-rs 0.0.3__tar.gz → 0.0.5__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.
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.github/workflows/_build_wheels.yaml +5 -1
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.github/workflows/ci.yaml +6 -7
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.github/workflows/release.yaml +3 -3
- bencode_rs-0.0.5/.pre-commit-config.yaml +27 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/Cargo.lock +18 -135
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/Cargo.toml +2 -5
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/PKG-INFO +13 -4
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/bencode_rs/__init__.py +8 -8
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/bencode_rs/__init__.pyi +7 -7
- bencode_rs-0.0.5/bencode_rs/py.typed +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/leak.py +55 -43
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/pyproject.toml +3 -6
- bencode_rs-0.0.5/readme.md +26 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/requirements.txt +9 -8
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/rustfmt.toml +12 -12
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/src/encode.rs +33 -34
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/src/lib.rs +0 -2
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/tests/test_2_decode.py +138 -138
- bencode_rs-0.0.3/readme.md +0 -17
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.coveragerc +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.gitattributes +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.github/renovate.json +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/.gitignore +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/LICENSE +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/src/decode.rs +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/tests/fixtures/56507.torrent.bin +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/tests/fixtures/ubuntu-22.04.2-desktop-amd64.iso.torrent.bin +0 -0
- {bencode_rs-0.0.3 → bencode_rs-0.0.5}/tests/test_1_encode.py +0 -0
|
@@ -8,6 +8,10 @@ jobs:
|
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
10
|
- uses: actions/checkout@v4
|
|
11
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
12
|
+
uses: actions/setup-python@v5
|
|
13
|
+
with:
|
|
14
|
+
python-version: '3.x'
|
|
11
15
|
- name: Build sdist
|
|
12
16
|
uses: PyO3/maturin-action@v1
|
|
13
17
|
with:
|
|
@@ -109,7 +113,7 @@ jobs:
|
|
|
109
113
|
|
|
110
114
|
merge-wheel-artifact:
|
|
111
115
|
runs-on: ubuntu-latest
|
|
112
|
-
needs: [
|
|
116
|
+
needs: ["linux", "windows", "macos", "sdist"]
|
|
113
117
|
steps:
|
|
114
118
|
- name: Merge Artifacts
|
|
115
119
|
uses: actions/upload-artifact/merge@v4
|
|
@@ -22,22 +22,21 @@ jobs:
|
|
|
22
22
|
strategy:
|
|
23
23
|
max-parallel: 5
|
|
24
24
|
matrix:
|
|
25
|
-
os: [
|
|
25
|
+
os: ["ubuntu-latest", "macos-13", "macos-14", "windows-latest"]
|
|
26
26
|
python-version:
|
|
27
|
-
- "3.8"
|
|
28
27
|
- "3.9"
|
|
29
28
|
- "3.10"
|
|
30
29
|
- "3.11"
|
|
31
30
|
- "3.12"
|
|
32
|
-
- "3.13
|
|
31
|
+
- "3.13"
|
|
33
32
|
|
|
34
33
|
runs-on: "${{ matrix.os }}"
|
|
35
34
|
|
|
36
|
-
needs: [
|
|
35
|
+
needs: [build]
|
|
37
36
|
|
|
38
37
|
steps:
|
|
39
38
|
- uses: actions/checkout@v4
|
|
40
|
-
- uses: actions/download-artifact@v4.1.
|
|
39
|
+
- uses: actions/download-artifact@v4.1.8
|
|
41
40
|
with:
|
|
42
41
|
name: wheel
|
|
43
42
|
path: dist
|
|
@@ -48,7 +47,7 @@ jobs:
|
|
|
48
47
|
python-version: ${{ matrix.python-version }}
|
|
49
48
|
cache: "pip" # caching pip dependencies
|
|
50
49
|
|
|
51
|
-
- run: pip install -U pip
|
|
50
|
+
- run: python -m pip install -U pip
|
|
52
51
|
- run: pip install bencode-rs --no-index --find-link ./dist/
|
|
53
52
|
- run: pip install -r requirements.txt
|
|
54
53
|
|
|
@@ -58,7 +57,7 @@ jobs:
|
|
|
58
57
|
|
|
59
58
|
audit:
|
|
60
59
|
name: Audit
|
|
61
|
-
needs: [
|
|
60
|
+
needs: [build]
|
|
62
61
|
runs-on: ubuntu-latest
|
|
63
62
|
steps:
|
|
64
63
|
- uses: actions/checkout@v4
|
|
@@ -11,15 +11,15 @@ jobs:
|
|
|
11
11
|
|
|
12
12
|
upload_all:
|
|
13
13
|
name: Upload wheels to PyPI
|
|
14
|
-
needs: [
|
|
14
|
+
needs: [build]
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
16
|
environment: pypi
|
|
17
17
|
permissions:
|
|
18
18
|
id-token: write
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/download-artifact@v4.1.
|
|
20
|
+
- uses: actions/download-artifact@v4.1.8
|
|
21
21
|
with:
|
|
22
22
|
name: wheel
|
|
23
23
|
path: dist
|
|
24
24
|
|
|
25
|
-
- uses: pypa/gh-action-pypi-publish@v1.
|
|
25
|
+
- uses: pypa/gh-action-pypi-publish@v1.11.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
exclude: '^.*\.bin$'
|
|
2
|
+
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
|
5
|
+
rev: v2.14.0
|
|
6
|
+
hooks:
|
|
7
|
+
- id: pretty-format-yaml
|
|
8
|
+
args: [--autofix, --indent, '2', '--preserve-quotes', --offset, '2']
|
|
9
|
+
|
|
10
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
11
|
+
rev: v5.0.0
|
|
12
|
+
hooks:
|
|
13
|
+
- id: check-case-conflict
|
|
14
|
+
- id: check-ast
|
|
15
|
+
- id: check-toml
|
|
16
|
+
- id: check-yaml
|
|
17
|
+
- id: check-merge-conflict
|
|
18
|
+
- id: debug-statements
|
|
19
|
+
- id: trailing-whitespace
|
|
20
|
+
- id: mixed-line-ending
|
|
21
|
+
args: [--fix=lf]
|
|
22
|
+
- id: end-of-file-fixer
|
|
23
|
+
|
|
24
|
+
- repo: https://github.com/psf/black
|
|
25
|
+
rev: 24.10.0
|
|
26
|
+
hooks:
|
|
27
|
+
- id: black
|
|
@@ -14,22 +14,17 @@ version = "0.0.0"
|
|
|
14
14
|
dependencies = [
|
|
15
15
|
"bytes",
|
|
16
16
|
"itoa",
|
|
17
|
+
"once_cell",
|
|
17
18
|
"pyo3",
|
|
18
19
|
"smallvec",
|
|
19
20
|
"syncpool",
|
|
20
21
|
]
|
|
21
22
|
|
|
22
|
-
[[package]]
|
|
23
|
-
name = "bitflags"
|
|
24
|
-
version = "2.5.0"
|
|
25
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
26
|
-
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
|
27
|
-
|
|
28
23
|
[[package]]
|
|
29
24
|
name = "bytes"
|
|
30
|
-
version = "1.
|
|
25
|
+
version = "1.8.0"
|
|
31
26
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
32
|
-
checksum = "
|
|
27
|
+
checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da"
|
|
33
28
|
|
|
34
29
|
[[package]]
|
|
35
30
|
name = "cfg-if"
|
|
@@ -39,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
|
39
34
|
|
|
40
35
|
[[package]]
|
|
41
36
|
name = "heck"
|
|
42
|
-
version = "0.
|
|
37
|
+
version = "0.5.0"
|
|
43
38
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
44
|
-
checksum = "
|
|
39
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
45
40
|
|
|
46
41
|
[[package]]
|
|
47
42
|
name = "indoc"
|
|
@@ -61,16 +56,6 @@ version = "0.2.155"
|
|
|
61
56
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
62
57
|
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
|
63
58
|
|
|
64
|
-
[[package]]
|
|
65
|
-
name = "lock_api"
|
|
66
|
-
version = "0.4.12"
|
|
67
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
-
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
|
69
|
-
dependencies = [
|
|
70
|
-
"autocfg",
|
|
71
|
-
"scopeguard",
|
|
72
|
-
]
|
|
73
|
-
|
|
74
59
|
[[package]]
|
|
75
60
|
name = "memoffset"
|
|
76
61
|
version = "0.9.1"
|
|
@@ -82,32 +67,9 @@ dependencies = [
|
|
|
82
67
|
|
|
83
68
|
[[package]]
|
|
84
69
|
name = "once_cell"
|
|
85
|
-
version = "1.
|
|
86
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
-
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
|
88
|
-
|
|
89
|
-
[[package]]
|
|
90
|
-
name = "parking_lot"
|
|
91
|
-
version = "0.12.2"
|
|
70
|
+
version = "1.20.2"
|
|
92
71
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
93
|
-
checksum = "
|
|
94
|
-
dependencies = [
|
|
95
|
-
"lock_api",
|
|
96
|
-
"parking_lot_core",
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
[[package]]
|
|
100
|
-
name = "parking_lot_core"
|
|
101
|
-
version = "0.9.10"
|
|
102
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
103
|
-
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
|
104
|
-
dependencies = [
|
|
105
|
-
"cfg-if",
|
|
106
|
-
"libc",
|
|
107
|
-
"redox_syscall",
|
|
108
|
-
"smallvec",
|
|
109
|
-
"windows-targets",
|
|
110
|
-
]
|
|
72
|
+
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
|
111
73
|
|
|
112
74
|
[[package]]
|
|
113
75
|
name = "portable-atomic"
|
|
@@ -126,15 +88,15 @@ dependencies = [
|
|
|
126
88
|
|
|
127
89
|
[[package]]
|
|
128
90
|
name = "pyo3"
|
|
129
|
-
version = "0.
|
|
91
|
+
version = "0.22.5"
|
|
130
92
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
|
-
checksum = "
|
|
93
|
+
checksum = "3d922163ba1f79c04bc49073ba7b32fd5a8d3b76a87c955921234b8e77333c51"
|
|
132
94
|
dependencies = [
|
|
133
95
|
"cfg-if",
|
|
134
96
|
"indoc",
|
|
135
97
|
"libc",
|
|
136
98
|
"memoffset",
|
|
137
|
-
"
|
|
99
|
+
"once_cell",
|
|
138
100
|
"portable-atomic",
|
|
139
101
|
"pyo3-build-config",
|
|
140
102
|
"pyo3-ffi",
|
|
@@ -144,9 +106,9 @@ dependencies = [
|
|
|
144
106
|
|
|
145
107
|
[[package]]
|
|
146
108
|
name = "pyo3-build-config"
|
|
147
|
-
version = "0.
|
|
109
|
+
version = "0.22.5"
|
|
148
110
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
149
|
-
checksum = "
|
|
111
|
+
checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179"
|
|
150
112
|
dependencies = [
|
|
151
113
|
"once_cell",
|
|
152
114
|
"target-lexicon",
|
|
@@ -154,9 +116,9 @@ dependencies = [
|
|
|
154
116
|
|
|
155
117
|
[[package]]
|
|
156
118
|
name = "pyo3-ffi"
|
|
157
|
-
version = "0.
|
|
119
|
+
version = "0.22.5"
|
|
158
120
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
159
|
-
checksum = "
|
|
121
|
+
checksum = "94845622d88ae274d2729fcefc850e63d7a3ddff5e3ce11bd88486db9f1d357d"
|
|
160
122
|
dependencies = [
|
|
161
123
|
"libc",
|
|
162
124
|
"pyo3-build-config",
|
|
@@ -164,9 +126,9 @@ dependencies = [
|
|
|
164
126
|
|
|
165
127
|
[[package]]
|
|
166
128
|
name = "pyo3-macros"
|
|
167
|
-
version = "0.
|
|
129
|
+
version = "0.22.5"
|
|
168
130
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
169
|
-
checksum = "
|
|
131
|
+
checksum = "e655aad15e09b94ffdb3ce3d217acf652e26bbc37697ef012f5e5e348c716e5e"
|
|
170
132
|
dependencies = [
|
|
171
133
|
"proc-macro2",
|
|
172
134
|
"pyo3-macros-backend",
|
|
@@ -176,9 +138,9 @@ dependencies = [
|
|
|
176
138
|
|
|
177
139
|
[[package]]
|
|
178
140
|
name = "pyo3-macros-backend"
|
|
179
|
-
version = "0.
|
|
141
|
+
version = "0.22.5"
|
|
180
142
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
181
|
-
checksum = "
|
|
143
|
+
checksum = "ae1e3f09eecd94618f60a455a23def79f79eba4dc561a97324bf9ac8c6df30ce"
|
|
182
144
|
dependencies = [
|
|
183
145
|
"heck",
|
|
184
146
|
"proc-macro2",
|
|
@@ -196,21 +158,6 @@ dependencies = [
|
|
|
196
158
|
"proc-macro2",
|
|
197
159
|
]
|
|
198
160
|
|
|
199
|
-
[[package]]
|
|
200
|
-
name = "redox_syscall"
|
|
201
|
-
version = "0.5.1"
|
|
202
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
203
|
-
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
|
|
204
|
-
dependencies = [
|
|
205
|
-
"bitflags",
|
|
206
|
-
]
|
|
207
|
-
|
|
208
|
-
[[package]]
|
|
209
|
-
name = "scopeguard"
|
|
210
|
-
version = "1.2.0"
|
|
211
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
212
|
-
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|
213
|
-
|
|
214
161
|
[[package]]
|
|
215
162
|
name = "smallvec"
|
|
216
163
|
version = "1.13.2"
|
|
@@ -251,67 +198,3 @@ name = "unindent"
|
|
|
251
198
|
version = "0.2.3"
|
|
252
199
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
253
200
|
checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce"
|
|
254
|
-
|
|
255
|
-
[[package]]
|
|
256
|
-
name = "windows-targets"
|
|
257
|
-
version = "0.52.5"
|
|
258
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
-
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
|
|
260
|
-
dependencies = [
|
|
261
|
-
"windows_aarch64_gnullvm",
|
|
262
|
-
"windows_aarch64_msvc",
|
|
263
|
-
"windows_i686_gnu",
|
|
264
|
-
"windows_i686_gnullvm",
|
|
265
|
-
"windows_i686_msvc",
|
|
266
|
-
"windows_x86_64_gnu",
|
|
267
|
-
"windows_x86_64_gnullvm",
|
|
268
|
-
"windows_x86_64_msvc",
|
|
269
|
-
]
|
|
270
|
-
|
|
271
|
-
[[package]]
|
|
272
|
-
name = "windows_aarch64_gnullvm"
|
|
273
|
-
version = "0.52.5"
|
|
274
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
275
|
-
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
|
|
276
|
-
|
|
277
|
-
[[package]]
|
|
278
|
-
name = "windows_aarch64_msvc"
|
|
279
|
-
version = "0.52.5"
|
|
280
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
281
|
-
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
|
|
282
|
-
|
|
283
|
-
[[package]]
|
|
284
|
-
name = "windows_i686_gnu"
|
|
285
|
-
version = "0.52.5"
|
|
286
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
287
|
-
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
|
|
288
|
-
|
|
289
|
-
[[package]]
|
|
290
|
-
name = "windows_i686_gnullvm"
|
|
291
|
-
version = "0.52.5"
|
|
292
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
293
|
-
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
|
|
294
|
-
|
|
295
|
-
[[package]]
|
|
296
|
-
name = "windows_i686_msvc"
|
|
297
|
-
version = "0.52.5"
|
|
298
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
299
|
-
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
|
|
300
|
-
|
|
301
|
-
[[package]]
|
|
302
|
-
name = "windows_x86_64_gnu"
|
|
303
|
-
version = "0.52.5"
|
|
304
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
305
|
-
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
|
|
306
|
-
|
|
307
|
-
[[package]]
|
|
308
|
-
name = "windows_x86_64_gnullvm"
|
|
309
|
-
version = "0.52.5"
|
|
310
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
311
|
-
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
|
|
312
|
-
|
|
313
|
-
[[package]]
|
|
314
|
-
name = "windows_x86_64_msvc"
|
|
315
|
-
version = "0.52.5"
|
|
316
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
317
|
-
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
|
@@ -11,9 +11,6 @@ crate-type = ["cdylib"]
|
|
|
11
11
|
bytes = "1.6.0"
|
|
12
12
|
syncpool = '0.1.6'
|
|
13
13
|
itoa = "1.0.11"
|
|
14
|
-
|
|
15
|
-
pyo3 = { version = "0.
|
|
14
|
+
once_cell = "1.19.0"
|
|
15
|
+
pyo3 = { version = "0.22.0", features = ['abi3-py39'] }
|
|
16
16
|
smallvec = "1.13.2"
|
|
17
|
-
|
|
18
|
-
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
|
|
19
|
-
# features = ["abi3-py38"]
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: bencode-rs
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
5
5
|
Classifier: License :: OSI Approved :: MIT License
|
|
6
6
|
Classifier: Programming Language :: Rust
|
|
7
7
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
8
8
|
License-File: LICENSE
|
|
9
|
-
Summary: a bencode parser
|
|
9
|
+
Summary: a bencode parser build with pyo3
|
|
10
10
|
Keywords: bittorrent,bencode,p2p
|
|
11
|
-
Requires-Python:
|
|
11
|
+
Requires-Python: ~=3.9
|
|
12
12
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
13
13
|
Project-URL: Homepage, https://github.com/trim21/bencode-rs
|
|
14
14
|
|
|
15
|
-
# A bencode serialize/deserialize library
|
|
15
|
+
# A bencode serialize/deserialize library written in Rust with pyo3
|
|
16
16
|
|
|
17
17
|
## install
|
|
18
18
|
|
|
@@ -30,3 +30,12 @@ assert bencode_rs.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}
|
|
|
30
30
|
assert bencode_rs.bencode({'hello': 'world'}) == b'd5:hello5:worlde'
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
## Notice
|
|
34
|
+
|
|
35
|
+
### decoding
|
|
36
|
+
there is no str/string in bencode, only bytes.
|
|
37
|
+
so we decode bencode bytes to python bytes, since it may not be a utf8 string.
|
|
38
|
+
|
|
39
|
+
### encoding
|
|
40
|
+
we encode python `True` as int `1` and `False` as int 0.
|
|
41
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from ._bencode import bencode, BencodeEncodeError, bdecode, BencodeDecodeError
|
|
2
|
-
|
|
3
|
-
__all__ = [
|
|
4
|
-
"bencode",
|
|
5
|
-
"BencodeEncodeError",
|
|
6
|
-
"bdecode",
|
|
7
|
-
"BencodeDecodeError",
|
|
8
|
-
]
|
|
1
|
+
from ._bencode import bencode, BencodeEncodeError, bdecode, BencodeDecodeError
|
|
2
|
+
|
|
3
|
+
__all__ = [
|
|
4
|
+
"bencode",
|
|
5
|
+
"BencodeEncodeError",
|
|
6
|
+
"bdecode",
|
|
7
|
+
"BencodeDecodeError",
|
|
8
|
+
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
def bencode(v: Any, /) -> bytes: ...
|
|
4
|
-
def bdecode(b: bytes, /) -> Any: ...
|
|
5
|
-
|
|
6
|
-
class BencodeEncodeError(Exception): ...
|
|
7
|
-
class BencodeDecodeError(Exception): ...
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
def bencode(v: Any, /) -> bytes: ...
|
|
4
|
+
def bdecode(b: bytes, /) -> Any: ...
|
|
5
|
+
|
|
6
|
+
class BencodeEncodeError(Exception): ...
|
|
7
|
+
class BencodeDecodeError(Exception): ...
|
|
File without changes
|
|
@@ -1,43 +1,55 @@
|
|
|
1
|
-
import random
|
|
2
|
-
import sys
|
|
3
|
-
import time
|
|
4
|
-
import tracemalloc
|
|
5
|
-
import gc
|
|
6
|
-
import secrets
|
|
7
|
-
|
|
8
|
-
from bencode_rs import BencodeEncodeError, bencode, bdecode, BencodeDecodeError
|
|
9
|
-
|
|
10
|
-
help(bencode)
|
|
11
|
-
help(bdecode)
|
|
12
|
-
|
|
13
|
-
sys.set_int_max_str_digits(20000)
|
|
14
|
-
|
|
15
|
-
tracemalloc.start()
|
|
16
|
-
|
|
17
|
-
while True:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import random
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
import tracemalloc
|
|
5
|
+
import gc
|
|
6
|
+
import secrets
|
|
7
|
+
|
|
8
|
+
from bencode_rs import BencodeEncodeError, bencode, bdecode, BencodeDecodeError
|
|
9
|
+
|
|
10
|
+
help(bencode)
|
|
11
|
+
help(bdecode)
|
|
12
|
+
|
|
13
|
+
sys.set_int_max_str_digits(20000)
|
|
14
|
+
|
|
15
|
+
tracemalloc.start()
|
|
16
|
+
|
|
17
|
+
while True:
|
|
18
|
+
s = b"100:" + secrets.token_bytes(10)
|
|
19
|
+
|
|
20
|
+
for c in [i for i in range(5000)]:
|
|
21
|
+
|
|
22
|
+
class C:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
bdecode(s)
|
|
27
|
+
except BencodeDecodeError:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
bencode([1, 2, "a", b"b", None])
|
|
32
|
+
except TypeError:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
bencode([1, 2, "a", b"b", C()])
|
|
37
|
+
except TypeError:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
bencode({"0": s, "2": [True, C()], "3": None})
|
|
42
|
+
except TypeError:
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
bencode({"1": C()})
|
|
47
|
+
except TypeError:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
gc.collect()
|
|
51
|
+
v = tracemalloc.get_tracemalloc_memory()
|
|
52
|
+
print(v)
|
|
53
|
+
if v > 10610992:
|
|
54
|
+
time.sleep(1000)
|
|
55
|
+
sys.exit(1)
|
|
@@ -4,9 +4,9 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bencode-rs"
|
|
7
|
-
version = "0.0.
|
|
8
|
-
requires-python = "
|
|
9
|
-
description = "a bencode parser
|
|
7
|
+
version = "0.0.5"
|
|
8
|
+
requires-python = "~=3.9"
|
|
9
|
+
description = "a bencode parser build with pyo3"
|
|
10
10
|
readme = "readme.md"
|
|
11
11
|
classifiers = [
|
|
12
12
|
"Development Status :: 2 - Pre-Alpha",
|
|
@@ -26,6 +26,3 @@ Homepage = 'https://github.com/trim21/bencode-rs'
|
|
|
26
26
|
[tool.maturin]
|
|
27
27
|
features = ["pyo3/extension-module"]
|
|
28
28
|
module-name = "bencode_rs._bencode"
|
|
29
|
-
|
|
30
|
-
[tool.cibuildwheel]
|
|
31
|
-
skip = ["pp*", "*-musllinux_i686"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# A bencode serialize/deserialize library written in Rust with pyo3
|
|
2
|
+
|
|
3
|
+
## install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
pip install bencode-rs
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## basic usage
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import bencode_rs
|
|
13
|
+
|
|
14
|
+
assert bencode_rs.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}
|
|
15
|
+
|
|
16
|
+
assert bencode_rs.bencode({'hello': 'world'}) == b'd5:hello5:worlde'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Notice
|
|
20
|
+
|
|
21
|
+
### decoding
|
|
22
|
+
there is no str/string in bencode, only bytes.
|
|
23
|
+
so we decode bencode bytes to python bytes, since it may not be a utf8 string.
|
|
24
|
+
|
|
25
|
+
### encoding
|
|
26
|
+
we encode python `True` as int `1` and `False` as int 0.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
# build
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
pytest
|
|
8
|
-
pytest-
|
|
1
|
+
# build
|
|
2
|
+
maturin>=1.5,<2.0
|
|
3
|
+
abi3audit
|
|
4
|
+
# lint
|
|
5
|
+
pre-commit
|
|
6
|
+
# testing
|
|
7
|
+
pytest
|
|
8
|
+
pytest-benchmark
|
|
9
|
+
pytest-github-actions-annotate-failures==0.2.0
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
reorder_imports = true
|
|
2
|
-
match_block_trailing_comma = true
|
|
3
|
-
newline_style = 'Unix'
|
|
4
|
-
use_field_init_shorthand = true
|
|
5
|
-
|
|
6
|
-
# nigntly
|
|
7
|
-
|
|
8
|
-
#imports_granularity = 'Module'
|
|
9
|
-
#group_imports = 'StdExternalCrate'
|
|
10
|
-
#imports_layout = "HorizontalVertical"
|
|
11
|
-
#force_multiline_blocks = true
|
|
12
|
-
#trailing_comma = 'Always'
|
|
1
|
+
reorder_imports = true
|
|
2
|
+
match_block_trailing_comma = true
|
|
3
|
+
newline_style = 'Unix'
|
|
4
|
+
use_field_init_shorthand = true
|
|
5
|
+
|
|
6
|
+
# nigntly
|
|
7
|
+
|
|
8
|
+
#imports_granularity = 'Module'
|
|
9
|
+
#group_imports = 'StdExternalCrate'
|
|
10
|
+
#imports_layout = "HorizontalVertical"
|
|
11
|
+
#force_multiline_blocks = true
|
|
12
|
+
#trailing_comma = 'Always'
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
use std::collections::HashSet;
|
|
2
|
-
|
|
3
1
|
use bytes::{BufMut, BytesMut};
|
|
4
|
-
use
|
|
2
|
+
use once_cell::sync::Lazy;
|
|
5
3
|
use pyo3::exceptions::PyValueError;
|
|
4
|
+
use pyo3::{
|
|
5
|
+
create_exception,
|
|
6
|
+
exceptions::PyTypeError,
|
|
7
|
+
prelude::*,
|
|
8
|
+
types::{PyBool, PyBytes, PyDict, PyInt, PyList, PyString, PyTuple},
|
|
9
|
+
};
|
|
6
10
|
use smallvec::SmallVec;
|
|
11
|
+
use std::collections::HashSet;
|
|
7
12
|
use syncpool::SyncPool;
|
|
8
13
|
|
|
9
|
-
create_exception!(
|
|
14
|
+
create_exception!(
|
|
15
|
+
bencode_rs,
|
|
16
|
+
BencodeEncodeError,
|
|
17
|
+
pyo3::exceptions::PyException
|
|
18
|
+
);
|
|
10
19
|
|
|
11
20
|
pub const MIB: usize = 1_048_576;
|
|
12
21
|
|
|
13
|
-
pub fn init() {
|
|
14
|
-
unsafe {
|
|
15
|
-
CONTEXT_POOL.replace(SyncPool::with_builder(Context::initializer));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
22
|
#[pyfunction]
|
|
20
23
|
#[pyo3(text_signature = "(v: Any, /)")]
|
|
21
24
|
pub fn bencode<'py>(py: Python<'py>, v: Bound<'py, PyAny>) -> PyResult<Bound<'py, PyBytes>> {
|
|
@@ -33,35 +36,32 @@ pub fn bencode<'py>(py: Python<'py>, v: Bound<'py, PyAny>) -> PyResult<Bound<'py
|
|
|
33
36
|
|
|
34
37
|
type EncodeError = BencodeEncodeError;
|
|
35
38
|
|
|
36
|
-
static mut CONTEXT_POOL:
|
|
39
|
+
static mut CONTEXT_POOL: Lazy<SyncPool<Context>> = Lazy::new(|| SyncPool::new());
|
|
37
40
|
|
|
38
41
|
fn get_ctx() -> Box<Context> {
|
|
39
42
|
unsafe {
|
|
40
|
-
CONTEXT_POOL.
|
|
43
|
+
return CONTEXT_POOL.get();
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
fn release_ctx(mut ctx: Box<Context>) -> () {
|
|
45
|
-
// do not store large buffers
|
|
46
|
-
// who encode torrent >= 100 MiB normally?
|
|
47
48
|
if ctx.buf.capacity() > 100 * MIB {
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
ctx.buf.clear();
|
|
51
52
|
ctx.seen.clear();
|
|
52
53
|
unsafe {
|
|
53
|
-
CONTEXT_POOL.
|
|
54
|
+
CONTEXT_POOL.put(ctx);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
58
|
struct Context {
|
|
59
59
|
buf: BytesMut,
|
|
60
60
|
seen: HashSet<usize>,
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
impl Context {
|
|
64
|
-
fn
|
|
63
|
+
impl Default for Context {
|
|
64
|
+
fn default() -> Self {
|
|
65
65
|
Self {
|
|
66
66
|
buf: BytesMut::with_capacity(4096),
|
|
67
67
|
seen: HashSet::with_capacity(100),
|
|
@@ -116,10 +116,10 @@ fn encode_any<'py>(ctx: &mut Context, py: Python<'py>, value: Bound<'py, PyAny>)
|
|
|
116
116
|
|
|
117
117
|
if let Ok(seq) = value.downcast::<PyList>() {
|
|
118
118
|
if ctx.seen.contains(&ptr) {
|
|
119
|
-
let repr = value.repr()
|
|
120
|
-
return Err(PyValueError::new_err(
|
|
121
|
-
|
|
122
|
-
));
|
|
119
|
+
let repr = value.repr()?.to_string();
|
|
120
|
+
return Err(PyValueError::new_err(format!(
|
|
121
|
+
"circular reference found {repr}"
|
|
122
|
+
)));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
ctx.seen.insert(ptr);
|
|
@@ -137,10 +137,10 @@ fn encode_any<'py>(ctx: &mut Context, py: Python<'py>, value: Bound<'py, PyAny>)
|
|
|
137
137
|
|
|
138
138
|
if let Ok(seq) = value.downcast::<PyTuple>() {
|
|
139
139
|
if ctx.seen.contains(&ptr) {
|
|
140
|
-
let repr = value.repr()
|
|
141
|
-
return Err(PyValueError::new_err(
|
|
142
|
-
|
|
143
|
-
));
|
|
140
|
+
let repr = value.repr()?.to_string();
|
|
141
|
+
return Err(PyValueError::new_err(format!(
|
|
142
|
+
"circular reference found {repr}"
|
|
143
|
+
)));
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
ctx.seen.insert(ptr);
|
|
@@ -156,10 +156,9 @@ fn encode_any<'py>(ctx: &mut Context, py: Python<'py>, value: Bound<'py, PyAny>)
|
|
|
156
156
|
return Ok(());
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
160
159
|
if let Ok(dict) = value.downcast::<PyDict>() {
|
|
161
160
|
if ctx.seen.contains(&ptr) {
|
|
162
|
-
let repr = value.repr()
|
|
161
|
+
let repr = value.repr()?.to_string();
|
|
163
162
|
return Err(PyValueError::new_err(format!(
|
|
164
163
|
"circular reference found: {repr}"
|
|
165
164
|
)));
|
|
@@ -197,13 +196,13 @@ fn encode_dict<'py>(ctx: &mut Context, py: Python<'py>, v: &Bound<'py, PyDict>)
|
|
|
197
196
|
for item in v.items().iter() {
|
|
198
197
|
let (key, value): (PyObject, Bound<'_, PyAny>) = item.extract()?;
|
|
199
198
|
|
|
200
|
-
if let Ok(d) = key.
|
|
199
|
+
if let Ok(d) = key.downcast_bound::<PyString>(py) {
|
|
201
200
|
let bb = d.to_string();
|
|
202
201
|
sv.push((bb, value));
|
|
203
202
|
continue;
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
if let Ok(d) = key.
|
|
205
|
+
if let Ok(d) = key.downcast_bound::<PyBytes>(py) {
|
|
207
206
|
sv.push((String::from_utf8(d.as_bytes().into())?, value));
|
|
208
207
|
continue;
|
|
209
208
|
}
|
|
@@ -211,7 +210,9 @@ fn encode_dict<'py>(ctx: &mut Context, py: Python<'py>, v: &Bound<'py, PyDict>)
|
|
|
211
210
|
let typ = value.get_type();
|
|
212
211
|
let name = typ.name()?;
|
|
213
212
|
|
|
214
|
-
return Err(PyTypeError::new_err(format!(
|
|
213
|
+
return Err(PyTypeError::new_err(format!(
|
|
214
|
+
"Unsupported type '{name}' as dict key"
|
|
215
|
+
)));
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
sv.sort_unstable_by(|a, b| a.0.cmp(&b.0));
|
|
@@ -220,9 +221,7 @@ fn encode_dict<'py>(ctx: &mut Context, py: Python<'py>, v: &Bound<'py, PyDict>)
|
|
|
220
221
|
for (key, _) in sv.clone() {
|
|
221
222
|
if let Some(lk) = last_key {
|
|
222
223
|
if lk == key {
|
|
223
|
-
return Err(EncodeError::new_err(format!(
|
|
224
|
-
"Duplicated keys {key}"
|
|
225
|
-
)));
|
|
224
|
+
return Err(EncodeError::new_err(format!("Duplicated keys {key}")));
|
|
226
225
|
}
|
|
227
226
|
}
|
|
228
227
|
|
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
from bencode_rs import BencodeDecodeError, bdecode
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def test_non_bytes_input():
|
|
9
|
-
with pytest.raises(TypeError):
|
|
10
|
-
bdecode("s") # type: ignore
|
|
11
|
-
|
|
12
|
-
with pytest.raises(TypeError):
|
|
13
|
-
bdecode(1) # type: ignore
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@pytest.mark.parametrize(
|
|
17
|
-
["raw", "expected"],
|
|
18
|
-
[
|
|
19
|
-
(b"i0e", 0),
|
|
20
|
-
(b"i1e", 1),
|
|
21
|
-
(b"i-123e", -123),
|
|
22
|
-
(b"i20022e", 20022),
|
|
23
|
-
(b"i-20022e", -20022),
|
|
24
|
-
],
|
|
25
|
-
)
|
|
26
|
-
def test_decode_int(raw, expected):
|
|
27
|
-
assert bdecode(raw) == expected
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@pytest.mark.parametrize(
|
|
31
|
-
"raw",
|
|
32
|
-
[
|
|
33
|
-
b"i-0e",
|
|
34
|
-
b"i-01e",
|
|
35
|
-
b"i01e",
|
|
36
|
-
b"i01",
|
|
37
|
-
b"ie",
|
|
38
|
-
b"i",
|
|
39
|
-
],
|
|
40
|
-
)
|
|
41
|
-
def test_decode_int_throw(raw):
|
|
42
|
-
with pytest.raises(BencodeDecodeError):
|
|
43
|
-
bdecode(raw)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def test_decode_str():
|
|
47
|
-
r = bytes.fromhex("0868de397935c05398eee852b7cf76a5b9801f90")
|
|
48
|
-
assert len(r) == 20
|
|
49
|
-
assert bdecode(b"20:" + r) == r
|
|
50
|
-
|
|
51
|
-
with pytest.raises(BencodeDecodeError):
|
|
52
|
-
bdecode(b"1:")
|
|
53
|
-
with pytest.raises(BencodeDecodeError):
|
|
54
|
-
bdecode(b"2:")
|
|
55
|
-
|
|
56
|
-
assert bdecode(b"0:") == b""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
@pytest.mark.parametrize(
|
|
60
|
-
"raw",
|
|
61
|
-
[
|
|
62
|
-
b"i123", # invalid int
|
|
63
|
-
b"i-0e",
|
|
64
|
-
b"i01e",
|
|
65
|
-
b"iabce",
|
|
66
|
-
b"1a2:qwer", # invalid str length
|
|
67
|
-
b"01:q", # invalid str length
|
|
68
|
-
b"10:q", # str length too big
|
|
69
|
-
b"a",
|
|
70
|
-
b"l",
|
|
71
|
-
b"lll",
|
|
72
|
-
# directory keys not sorted for {'foo': 1, 'spam': 2}
|
|
73
|
-
b"d3:foo4:spam3:bari42ee",
|
|
74
|
-
],
|
|
75
|
-
)
|
|
76
|
-
def test_bad_case(raw: bytes):
|
|
77
|
-
with pytest.raises(BencodeDecodeError):
|
|
78
|
-
bdecode(raw)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@pytest.mark.parametrize(
|
|
82
|
-
["raw", "expected"],
|
|
83
|
-
[
|
|
84
|
-
(b"le", []),
|
|
85
|
-
(b"llee", [[]]),
|
|
86
|
-
(b"lli1eelee", [[1], []]),
|
|
87
|
-
],
|
|
88
|
-
)
|
|
89
|
-
def test_list(raw: bytes, expected: Any):
|
|
90
|
-
assert bdecode(raw) == expected
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
@pytest.mark.parametrize(
|
|
94
|
-
["raw", "expected"],
|
|
95
|
-
[
|
|
96
|
-
(b"i1e", 1),
|
|
97
|
-
(b"i4927586304e", 4927586304),
|
|
98
|
-
(b"0:", b""),
|
|
99
|
-
(b"4:spam", b"spam"),
|
|
100
|
-
(b"i-3e", -3),
|
|
101
|
-
(b"i-9223372036854775808e", -9223372036854775808), # longlong int +1
|
|
102
|
-
(b"i9223372036854775808e", 9223372036854775808), # longlong int +1
|
|
103
|
-
(b"i18446744073709551616e", 18446744073709551616), # unsigned long long +1
|
|
104
|
-
# long long int range -9223372036854775808, 9223372036854775807
|
|
105
|
-
(b"i-9223372036854775808e", -9223372036854775808),
|
|
106
|
-
(b"i9223372036854775808e", 9223372036854775808),
|
|
107
|
-
(b"le", []),
|
|
108
|
-
(b"l4:spam4:eggse", [b"spam", b"eggs"]),
|
|
109
|
-
# (b"de", {}),
|
|
110
|
-
(b"d3:cow3:moo4:spam4:eggse", {b"cow": b"moo", b"spam": b"eggs"}),
|
|
111
|
-
(b"d4:spaml1:a1:bee", {b"spam": [b"a", b"b"]}),
|
|
112
|
-
(b"d0:4:spam3:fooi42ee", {b"": b"spam", b"foo": 42}),
|
|
113
|
-
],
|
|
114
|
-
)
|
|
115
|
-
def test_basic(raw: bytes, expected: Any):
|
|
116
|
-
assert bdecode(raw) == expected
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def test_decode1():
|
|
120
|
-
assert bdecode(b"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe") == {
|
|
121
|
-
b"a": {b"id": b"abcdefghij0123456789"},
|
|
122
|
-
b"q": b"ping",
|
|
123
|
-
b"t": b"aa",
|
|
124
|
-
b"y": b"q",
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
# @pytest.mark.parametrize(
|
|
131
|
-
# ["raw", "expected"],
|
|
132
|
-
# [
|
|
133
|
-
# (b"d3:cow3:moo4:spam4:eggse", {"cow": b"moo", "spam": b"eggs"}),
|
|
134
|
-
# (b"d4:spaml1:a1:bee", {"spam": [b"a", b"b"]}),
|
|
135
|
-
# ],
|
|
136
|
-
# )
|
|
137
|
-
# def test_dict_str_key(raw: bytes, expected: Any):
|
|
138
|
-
# assert bdecode(raw, str_key=True) == expected
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from bencode_rs import BencodeDecodeError, bdecode
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_non_bytes_input():
|
|
9
|
+
with pytest.raises(TypeError):
|
|
10
|
+
bdecode("s") # type: ignore
|
|
11
|
+
|
|
12
|
+
with pytest.raises(TypeError):
|
|
13
|
+
bdecode(1) # type: ignore
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.parametrize(
|
|
17
|
+
["raw", "expected"],
|
|
18
|
+
[
|
|
19
|
+
(b"i0e", 0),
|
|
20
|
+
(b"i1e", 1),
|
|
21
|
+
(b"i-123e", -123),
|
|
22
|
+
(b"i20022e", 20022),
|
|
23
|
+
(b"i-20022e", -20022),
|
|
24
|
+
],
|
|
25
|
+
)
|
|
26
|
+
def test_decode_int(raw, expected):
|
|
27
|
+
assert bdecode(raw) == expected
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.mark.parametrize(
|
|
31
|
+
"raw",
|
|
32
|
+
[
|
|
33
|
+
b"i-0e",
|
|
34
|
+
b"i-01e",
|
|
35
|
+
b"i01e",
|
|
36
|
+
b"i01",
|
|
37
|
+
b"ie",
|
|
38
|
+
b"i",
|
|
39
|
+
],
|
|
40
|
+
)
|
|
41
|
+
def test_decode_int_throw(raw):
|
|
42
|
+
with pytest.raises(BencodeDecodeError):
|
|
43
|
+
bdecode(raw)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_decode_str():
|
|
47
|
+
r = bytes.fromhex("0868de397935c05398eee852b7cf76a5b9801f90")
|
|
48
|
+
assert len(r) == 20
|
|
49
|
+
assert bdecode(b"20:" + r) == r
|
|
50
|
+
|
|
51
|
+
with pytest.raises(BencodeDecodeError):
|
|
52
|
+
bdecode(b"1:")
|
|
53
|
+
with pytest.raises(BencodeDecodeError):
|
|
54
|
+
bdecode(b"2:")
|
|
55
|
+
|
|
56
|
+
assert bdecode(b"0:") == b""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.parametrize(
|
|
60
|
+
"raw",
|
|
61
|
+
[
|
|
62
|
+
b"i123", # invalid int
|
|
63
|
+
b"i-0e",
|
|
64
|
+
b"i01e",
|
|
65
|
+
b"iabce",
|
|
66
|
+
b"1a2:qwer", # invalid str length
|
|
67
|
+
b"01:q", # invalid str length
|
|
68
|
+
b"10:q", # str length too big
|
|
69
|
+
b"a",
|
|
70
|
+
b"l",
|
|
71
|
+
b"lll",
|
|
72
|
+
# directory keys not sorted for {'foo': 1, 'spam': 2}
|
|
73
|
+
b"d3:foo4:spam3:bari42ee",
|
|
74
|
+
],
|
|
75
|
+
)
|
|
76
|
+
def test_bad_case(raw: bytes):
|
|
77
|
+
with pytest.raises(BencodeDecodeError):
|
|
78
|
+
bdecode(raw)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize(
|
|
82
|
+
["raw", "expected"],
|
|
83
|
+
[
|
|
84
|
+
(b"le", []),
|
|
85
|
+
(b"llee", [[]]),
|
|
86
|
+
(b"lli1eelee", [[1], []]),
|
|
87
|
+
],
|
|
88
|
+
)
|
|
89
|
+
def test_list(raw: bytes, expected: Any):
|
|
90
|
+
assert bdecode(raw) == expected
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@pytest.mark.parametrize(
|
|
94
|
+
["raw", "expected"],
|
|
95
|
+
[
|
|
96
|
+
(b"i1e", 1),
|
|
97
|
+
(b"i4927586304e", 4927586304),
|
|
98
|
+
(b"0:", b""),
|
|
99
|
+
(b"4:spam", b"spam"),
|
|
100
|
+
(b"i-3e", -3),
|
|
101
|
+
(b"i-9223372036854775808e", -9223372036854775808), # longlong int +1
|
|
102
|
+
(b"i9223372036854775808e", 9223372036854775808), # longlong int +1
|
|
103
|
+
(b"i18446744073709551616e", 18446744073709551616), # unsigned long long +1
|
|
104
|
+
# long long int range -9223372036854775808, 9223372036854775807
|
|
105
|
+
(b"i-9223372036854775808e", -9223372036854775808),
|
|
106
|
+
(b"i9223372036854775808e", 9223372036854775808),
|
|
107
|
+
(b"le", []),
|
|
108
|
+
(b"l4:spam4:eggse", [b"spam", b"eggs"]),
|
|
109
|
+
# (b"de", {}),
|
|
110
|
+
(b"d3:cow3:moo4:spam4:eggse", {b"cow": b"moo", b"spam": b"eggs"}),
|
|
111
|
+
(b"d4:spaml1:a1:bee", {b"spam": [b"a", b"b"]}),
|
|
112
|
+
(b"d0:4:spam3:fooi42ee", {b"": b"spam", b"foo": 42}),
|
|
113
|
+
],
|
|
114
|
+
)
|
|
115
|
+
def test_basic(raw: bytes, expected: Any):
|
|
116
|
+
assert bdecode(raw) == expected
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_decode1():
|
|
120
|
+
assert bdecode(b"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe") == {
|
|
121
|
+
b"a": {b"id": b"abcdefghij0123456789"},
|
|
122
|
+
b"q": b"ping",
|
|
123
|
+
b"t": b"aa",
|
|
124
|
+
b"y": b"q",
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
#
|
|
129
|
+
#
|
|
130
|
+
# @pytest.mark.parametrize(
|
|
131
|
+
# ["raw", "expected"],
|
|
132
|
+
# [
|
|
133
|
+
# (b"d3:cow3:moo4:spam4:eggse", {"cow": b"moo", "spam": b"eggs"}),
|
|
134
|
+
# (b"d4:spaml1:a1:bee", {"spam": [b"a", b"b"]}),
|
|
135
|
+
# ],
|
|
136
|
+
# )
|
|
137
|
+
# def test_dict_str_key(raw: bytes, expected: Any):
|
|
138
|
+
# assert bdecode(raw, str_key=True) == expected
|
bencode_rs-0.0.3/readme.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# A bencode serialize/deserialize library writte in Rust
|
|
2
|
-
|
|
3
|
-
## install
|
|
4
|
-
|
|
5
|
-
```shell
|
|
6
|
-
pip install bencode-rs
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## basic usage
|
|
10
|
-
|
|
11
|
-
```python
|
|
12
|
-
import bencode_rs
|
|
13
|
-
|
|
14
|
-
assert bencode_rs.bdecode(b"d4:spaml1:a1:bee") == {b"spam": [b"a", b"b"]}
|
|
15
|
-
|
|
16
|
-
assert bencode_rs.bencode({'hello': 'world'}) == b'd5:hello5:worlde'
|
|
17
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bencode_rs-0.0.3 → bencode_rs-0.0.5}/tests/fixtures/ubuntu-22.04.2-desktop-amd64.iso.torrent.bin
RENAMED
|
File without changes
|
|
File without changes
|