summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock622
-rw-r--r--Cargo.toml11
-rw-r--r--pyproject.toml4
-rw-r--r--src/lib.rs251
4 files changed, 502 insertions, 386 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 999805e..47d1579 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,275 +1,372 @@
1# This file is automatically @generated by Cargo. 1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing. 2# It is not intended for manual editing.
3version = 3 3version = 4
4 4
5[[package]] 5[[package]]
6name = "adblock" 6name = "adblock"
7version = "0.5.6" 7version = "0.7.0"
8dependencies = [
9 "adblock 0.11.1",
10 "pyo3",
11]
12
13[[package]]
14name = "adblock"
15version = "0.11.1"
8source = "registry+https://github.com/rust-lang/crates.io-index" 16source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "27785ef5b89bc88fd2def3e1ecfefdf5ec1583795b916667afd15b13058f8315" 17checksum = "5d6a431e8b3c95fa49574ed925b85fe34978f5917168c8ce4dcf729af861fc87"
10dependencies = [ 18dependencies = [
11 "addr", 19 "addr",
12 "base64", 20 "base64",
13 "bitflags", 21 "bitflags",
14 "flate2", 22 "flatbuffers",
15 "idna", 23 "idna",
16 "itertools", 24 "itertools",
25 "memchr",
17 "once_cell", 26 "once_cell",
18 "percent-encoding", 27 "percent-encoding",
28 "precomputed-hash",
19 "regex", 29 "regex",
20 "rmp-serde 0.13.7", 30 "rmp-serde",
21 "rmp-serde 0.15.5", 31 "rustc-hash",
22 "seahash", 32 "seahash",
23 "serde", 33 "serde",
24 "twoway", 34 "serde_json",
35 "thiserror",
25 "url", 36 "url",
26] 37]
27 38
28[[package]] 39[[package]]
29name = "adblock"
30version = "0.6.0"
31dependencies = [
32 "adblock 0.5.6",
33 "pyo3",
34]
35
36[[package]]
37name = "addr" 40name = "addr"
38version = "0.14.0" 41version = "0.15.6"
39source = "registry+https://github.com/rust-lang/crates.io-index" 42source = "registry+https://github.com/rust-lang/crates.io-index"
40checksum = "c54ccac949a2afafdfc889e15c753bbc6ee8783e026bbe3d057b00b13907db70" 43checksum = "a93b8a41dbe230ad5087cc721f8d41611de654542180586b315d9f4cf6b72bef"
41dependencies = [ 44dependencies = [
42 "psl", 45 "psl",
43 "psl-types", 46 "psl-types",
44] 47]
45 48
46[[package]] 49[[package]]
47name = "adler"
48version = "1.0.2"
49source = "registry+https://github.com/rust-lang/crates.io-index"
50checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
51
52[[package]]
53name = "aho-corasick" 50name = "aho-corasick"
54version = "0.7.18" 51version = "1.1.4"
55source = "registry+https://github.com/rust-lang/crates.io-index" 52source = "registry+https://github.com/rust-lang/crates.io-index"
56checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" 53checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
57dependencies = [ 54dependencies = [
58 "memchr", 55 "memchr",
59] 56]
60 57
61[[package]] 58[[package]]
62name = "autocfg" 59name = "autocfg"
63version = "1.1.0" 60version = "1.5.0"
64source = "registry+https://github.com/rust-lang/crates.io-index" 61source = "registry+https://github.com/rust-lang/crates.io-index"
65checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 62checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
66 63
67[[package]] 64[[package]]
68name = "base64" 65name = "base64"
69version = "0.13.0" 66version = "0.22.1"
70source = "registry+https://github.com/rust-lang/crates.io-index" 67source = "registry+https://github.com/rust-lang/crates.io-index"
71checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 68checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
72 69
73[[package]] 70[[package]]
74name = "bitflags" 71name = "bitflags"
75version = "1.3.2" 72version = "2.10.0"
76source = "registry+https://github.com/rust-lang/crates.io-index" 73source = "registry+https://github.com/rust-lang/crates.io-index"
77checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 74checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
75dependencies = [
76 "serde_core",
77]
78 78
79[[package]] 79[[package]]
80name = "byteorder" 80name = "byteorder"
81version = "1.4.3" 81version = "1.5.0"
82source = "registry+https://github.com/rust-lang/crates.io-index" 82source = "registry+https://github.com/rust-lang/crates.io-index"
83checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 83checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
84 84
85[[package]] 85[[package]]
86name = "cfg-if" 86name = "cfg-if"
87version = "1.0.0" 87version = "1.0.4"
88source = "registry+https://github.com/rust-lang/crates.io-index" 88source = "registry+https://github.com/rust-lang/crates.io-index"
89checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 89checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
90 90
91[[package]] 91[[package]]
92name = "crc32fast" 92name = "displaydoc"
93version = "1.3.2" 93version = "0.2.5"
94source = "registry+https://github.com/rust-lang/crates.io-index" 94source = "registry+https://github.com/rust-lang/crates.io-index"
95checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" 95checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
96dependencies = [ 96dependencies = [
97 "cfg-if", 97 "proc-macro2",
98 "quote",
99 "syn",
98] 100]
99 101
100[[package]] 102[[package]]
101name = "either" 103name = "either"
102version = "1.7.0" 104version = "1.15.0"
103source = "registry+https://github.com/rust-lang/crates.io-index" 105source = "registry+https://github.com/rust-lang/crates.io-index"
104checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" 106checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
105 107
106[[package]] 108[[package]]
107name = "flate2" 109name = "flatbuffers"
108version = "1.0.24" 110version = "25.9.23"
109source = "registry+https://github.com/rust-lang/crates.io-index" 111source = "registry+https://github.com/rust-lang/crates.io-index"
110checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" 112checksum = "09b6620799e7340ebd9968d2e0708eb82cf1971e9a16821e2091b6d6e475eed5"
111dependencies = [ 113dependencies = [
112 "crc32fast", 114 "bitflags",
113 "miniz_oxide", 115 "rustc_version",
114] 116]
115 117
116[[package]] 118[[package]]
117name = "form_urlencoded" 119name = "form_urlencoded"
118version = "1.0.1" 120version = "1.2.2"
119source = "registry+https://github.com/rust-lang/crates.io-index" 121source = "registry+https://github.com/rust-lang/crates.io-index"
120checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 122checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
121dependencies = [ 123dependencies = [
122 "matches",
123 "percent-encoding", 124 "percent-encoding",
124] 125]
125 126
126[[package]] 127[[package]]
127name = "idna" 128name = "heck"
128version = "0.2.3" 129version = "0.5.0"
130source = "registry+https://github.com/rust-lang/crates.io-index"
131checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
132
133[[package]]
134name = "icu_collections"
135version = "2.1.1"
129source = "registry+https://github.com/rust-lang/crates.io-index" 136source = "registry+https://github.com/rust-lang/crates.io-index"
130checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" 137checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"
131dependencies = [ 138dependencies = [
132 "matches", 139 "displaydoc",
133 "unicode-bidi", 140 "potential_utf",
134 "unicode-normalization", 141 "yoke",
142 "zerofrom",
143 "zerovec",
135] 144]
136 145
137[[package]] 146[[package]]
138name = "indoc" 147name = "icu_locale_core"
139version = "1.0.6" 148version = "2.1.1"
140source = "registry+https://github.com/rust-lang/crates.io-index" 149source = "registry+https://github.com/rust-lang/crates.io-index"
141checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e" 150checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"
151dependencies = [
152 "displaydoc",
153 "litemap",
154 "tinystr",
155 "writeable",
156 "zerovec",
157]
142 158
143[[package]] 159[[package]]
144name = "itertools" 160name = "icu_normalizer"
145version = "0.10.3" 161version = "2.1.1"
146source = "registry+https://github.com/rust-lang/crates.io-index" 162source = "registry+https://github.com/rust-lang/crates.io-index"
147checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" 163checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"
148dependencies = [ 164dependencies = [
149 "either", 165 "icu_collections",
166 "icu_normalizer_data",
167 "icu_properties",
168 "icu_provider",
169 "smallvec",
170 "zerovec",
150] 171]
151 172
152[[package]] 173[[package]]
153name = "libc" 174name = "icu_normalizer_data"
154version = "0.2.126" 175version = "2.1.1"
155source = "registry+https://github.com/rust-lang/crates.io-index" 176source = "registry+https://github.com/rust-lang/crates.io-index"
156checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" 177checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
157 178
158[[package]] 179[[package]]
159name = "lock_api" 180name = "icu_properties"
160version = "0.4.7" 181version = "2.1.1"
161source = "registry+https://github.com/rust-lang/crates.io-index" 182source = "registry+https://github.com/rust-lang/crates.io-index"
162checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" 183checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99"
163dependencies = [ 184dependencies = [
164 "autocfg", 185 "icu_collections",
165 "scopeguard", 186 "icu_locale_core",
187 "icu_properties_data",
188 "icu_provider",
189 "zerotrie",
190 "zerovec",
166] 191]
167 192
168[[package]] 193[[package]]
169name = "matches" 194name = "icu_properties_data"
170version = "0.1.9" 195version = "2.1.1"
171source = "registry+https://github.com/rust-lang/crates.io-index" 196source = "registry+https://github.com/rust-lang/crates.io-index"
172checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" 197checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899"
173 198
174[[package]] 199[[package]]
175name = "memchr" 200name = "icu_provider"
176version = "2.5.0" 201version = "2.1.1"
177source = "registry+https://github.com/rust-lang/crates.io-index" 202source = "registry+https://github.com/rust-lang/crates.io-index"
178checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 203checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"
204dependencies = [
205 "displaydoc",
206 "icu_locale_core",
207 "writeable",
208 "yoke",
209 "zerofrom",
210 "zerotrie",
211 "zerovec",
212]
179 213
180[[package]] 214[[package]]
181name = "miniz_oxide" 215name = "idna"
182version = "0.5.3" 216version = "1.1.0"
183source = "registry+https://github.com/rust-lang/crates.io-index" 217source = "registry+https://github.com/rust-lang/crates.io-index"
184checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" 218checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
185dependencies = [ 219dependencies = [
186 "adler", 220 "idna_adapter",
221 "smallvec",
222 "utf8_iter",
187] 223]
188 224
189[[package]] 225[[package]]
190name = "num-traits" 226name = "idna_adapter"
191version = "0.2.15" 227version = "1.2.1"
192source = "registry+https://github.com/rust-lang/crates.io-index" 228source = "registry+https://github.com/rust-lang/crates.io-index"
193checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 229checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344"
194dependencies = [ 230dependencies = [
195 "autocfg", 231 "icu_normalizer",
232 "icu_properties",
196] 233]
197 234
198[[package]] 235[[package]]
199name = "once_cell" 236name = "indoc"
200version = "1.13.0" 237version = "2.0.7"
201source = "registry+https://github.com/rust-lang/crates.io-index" 238source = "registry+https://github.com/rust-lang/crates.io-index"
202checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" 239checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
240dependencies = [
241 "rustversion",
242]
203 243
204[[package]] 244[[package]]
205name = "parking_lot" 245name = "itertools"
206version = "0.12.1" 246version = "0.13.0"
207source = "registry+https://github.com/rust-lang/crates.io-index" 247source = "registry+https://github.com/rust-lang/crates.io-index"
208checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 248checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
209dependencies = [ 249dependencies = [
210 "lock_api", 250 "either",
211 "parking_lot_core",
212] 251]
213 252
214[[package]] 253[[package]]
215name = "parking_lot_core" 254name = "itoa"
216version = "0.9.3" 255version = "1.0.15"
256source = "registry+https://github.com/rust-lang/crates.io-index"
257checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
258
259[[package]]
260name = "libc"
261version = "0.2.177"
262source = "registry+https://github.com/rust-lang/crates.io-index"
263checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
264
265[[package]]
266name = "litemap"
267version = "0.8.1"
217source = "registry+https://github.com/rust-lang/crates.io-index" 268source = "registry+https://github.com/rust-lang/crates.io-index"
218checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" 269checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
270
271[[package]]
272name = "memchr"
273version = "2.7.6"
274source = "registry+https://github.com/rust-lang/crates.io-index"
275checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
276
277[[package]]
278name = "memoffset"
279version = "0.9.1"
280source = "registry+https://github.com/rust-lang/crates.io-index"
281checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
219dependencies = [ 282dependencies = [
220 "cfg-if", 283 "autocfg",
221 "libc",
222 "redox_syscall",
223 "smallvec",
224 "windows-sys",
225] 284]
226 285
227[[package]] 286[[package]]
287name = "num-traits"
288version = "0.2.19"
289source = "registry+https://github.com/rust-lang/crates.io-index"
290checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
291dependencies = [
292 "autocfg",
293]
294
295[[package]]
296name = "once_cell"
297version = "1.21.3"
298source = "registry+https://github.com/rust-lang/crates.io-index"
299checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
300
301[[package]]
228name = "paste" 302name = "paste"
229version = "1.0.7" 303version = "1.0.15"
230source = "registry+https://github.com/rust-lang/crates.io-index" 304source = "registry+https://github.com/rust-lang/crates.io-index"
231checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" 305checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
232 306
233[[package]] 307[[package]]
234name = "percent-encoding" 308name = "percent-encoding"
235version = "2.1.0" 309version = "2.3.2"
236source = "registry+https://github.com/rust-lang/crates.io-index" 310source = "registry+https://github.com/rust-lang/crates.io-index"
237checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 311checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
312
313[[package]]
314name = "portable-atomic"
315version = "1.11.1"
316source = "registry+https://github.com/rust-lang/crates.io-index"
317checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
318
319[[package]]
320name = "potential_utf"
321version = "0.1.4"
322source = "registry+https://github.com/rust-lang/crates.io-index"
323checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"
324dependencies = [
325 "zerovec",
326]
327
328[[package]]
329name = "precomputed-hash"
330version = "0.1.1"
331source = "registry+https://github.com/rust-lang/crates.io-index"
332checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
238 333
239[[package]] 334[[package]]
240name = "proc-macro2" 335name = "proc-macro2"
241version = "1.0.40" 336version = "1.0.103"
242source = "registry+https://github.com/rust-lang/crates.io-index" 337source = "registry+https://github.com/rust-lang/crates.io-index"
243checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" 338checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
244dependencies = [ 339dependencies = [
245 "unicode-ident", 340 "unicode-ident",
246] 341]
247 342
248[[package]] 343[[package]]
249name = "psl" 344name = "psl"
250version = "2.0.90" 345version = "2.1.161"
251source = "registry+https://github.com/rust-lang/crates.io-index" 346source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "7e9c7d362659b525758d09e2a3ae965e371b347605e5fb2bc5bec5c2a1ecf41b" 347checksum = "96f36d5dda1aa6585ce2a74b0ae1a85e530db47b0186cd06b63f09dbd8035fc6"
253dependencies = [ 348dependencies = [
254 "psl-types", 349 "psl-types",
255] 350]
256 351
257[[package]] 352[[package]]
258name = "psl-types" 353name = "psl-types"
259version = "2.0.10" 354version = "2.0.11"
260source = "registry+https://github.com/rust-lang/crates.io-index" 355source = "registry+https://github.com/rust-lang/crates.io-index"
261checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" 356checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac"
262 357
263[[package]] 358[[package]]
264name = "pyo3" 359name = "pyo3"
265version = "0.16.5" 360version = "0.22.6"
266source = "registry+https://github.com/rust-lang/crates.io-index" 361source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" 362checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
268dependencies = [ 363dependencies = [
269 "cfg-if", 364 "cfg-if",
270 "indoc", 365 "indoc",
271 "libc", 366 "libc",
272 "parking_lot", 367 "memoffset",
368 "once_cell",
369 "portable-atomic",
273 "pyo3-build-config", 370 "pyo3-build-config",
274 "pyo3-ffi", 371 "pyo3-ffi",
275 "pyo3-macros", 372 "pyo3-macros",
@@ -278,9 +375,9 @@ dependencies = [
278 375
279[[package]] 376[[package]]
280name = "pyo3-build-config" 377name = "pyo3-build-config"
281version = "0.16.5" 378version = "0.22.6"
282source = "registry+https://github.com/rust-lang/crates.io-index" 379source = "registry+https://github.com/rust-lang/crates.io-index"
283checksum = "b5b65b546c35d8a3b1b2f0ddbac7c6a569d759f357f2b9df884f5d6b719152c8" 380checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
284dependencies = [ 381dependencies = [
285 "once_cell", 382 "once_cell",
286 "target-lexicon", 383 "target-lexicon",
@@ -288,9 +385,9 @@ dependencies = [
288 385
289[[package]] 386[[package]]
290name = "pyo3-ffi" 387name = "pyo3-ffi"
291version = "0.16.5" 388version = "0.22.6"
292source = "registry+https://github.com/rust-lang/crates.io-index" 389source = "registry+https://github.com/rust-lang/crates.io-index"
293checksum = "c275a07127c1aca33031a563e384ffdd485aee34ef131116fcd58e3430d1742b" 390checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
294dependencies = [ 391dependencies = [
295 "libc", 392 "libc",
296 "pyo3-build-config", 393 "pyo3-build-config",
@@ -298,9 +395,9 @@ dependencies = [
298 395
299[[package]] 396[[package]]
300name = "pyo3-macros" 397name = "pyo3-macros"
301version = "0.16.5" 398version = "0.22.6"
302source = "registry+https://github.com/rust-lang/crates.io-index" 399source = "registry+https://github.com/rust-lang/crates.io-index"
303checksum = "284fc4485bfbcc9850a6d661d627783f18d19c2ab55880b021671c4ba83e90f7" 400checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
304dependencies = [ 401dependencies = [
305 "proc-macro2", 402 "proc-macro2",
306 "pyo3-macros-backend", 403 "pyo3-macros-backend",
@@ -310,38 +407,43 @@ dependencies = [
310 407
311[[package]] 408[[package]]
312name = "pyo3-macros-backend" 409name = "pyo3-macros-backend"
313version = "0.16.5" 410version = "0.22.6"
314source = "registry+https://github.com/rust-lang/crates.io-index" 411source = "registry+https://github.com/rust-lang/crates.io-index"
315checksum = "53bda0f58f73f5c5429693c96ed57f7abdb38fdfc28ae06da4101a257adb7faf" 412checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
316dependencies = [ 413dependencies = [
414 "heck",
317 "proc-macro2", 415 "proc-macro2",
416 "pyo3-build-config",
318 "quote", 417 "quote",
319 "syn", 418 "syn",
320] 419]
321 420
322[[package]] 421[[package]]
323name = "quote" 422name = "quote"
324version = "1.0.20" 423version = "1.0.42"
325source = "registry+https://github.com/rust-lang/crates.io-index" 424source = "registry+https://github.com/rust-lang/crates.io-index"
326checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" 425checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
327dependencies = [ 426dependencies = [
328 "proc-macro2", 427 "proc-macro2",
329] 428]
330 429
331[[package]] 430[[package]]
332name = "redox_syscall" 431name = "regex"
333version = "0.2.13" 432version = "1.12.2"
334source = "registry+https://github.com/rust-lang/crates.io-index" 433source = "registry+https://github.com/rust-lang/crates.io-index"
335checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" 434checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
336dependencies = [ 435dependencies = [
337 "bitflags", 436 "aho-corasick",
437 "memchr",
438 "regex-automata",
439 "regex-syntax",
338] 440]
339 441
340[[package]] 442[[package]]
341name = "regex" 443name = "regex-automata"
342version = "1.6.0" 444version = "0.4.13"
343source = "registry+https://github.com/rust-lang/crates.io-index" 445source = "registry+https://github.com/rust-lang/crates.io-index"
344checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" 446checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
345dependencies = [ 447dependencies = [
346 "aho-corasick", 448 "aho-corasick",
347 "memchr", 449 "memchr",
@@ -350,15 +452,15 @@ dependencies = [
350 452
351[[package]] 453[[package]]
352name = "regex-syntax" 454name = "regex-syntax"
353version = "0.6.27" 455version = "0.8.8"
354source = "registry+https://github.com/rust-lang/crates.io-index" 456source = "registry+https://github.com/rust-lang/crates.io-index"
355checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" 457checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
356 458
357[[package]] 459[[package]]
358name = "rmp" 460name = "rmp"
359version = "0.8.11" 461version = "0.8.14"
360source = "registry+https://github.com/rust-lang/crates.io-index" 462source = "registry+https://github.com/rust-lang/crates.io-index"
361checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" 463checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4"
362dependencies = [ 464dependencies = [
363 "byteorder", 465 "byteorder",
364 "num-traits", 466 "num-traits",
@@ -367,9 +469,9 @@ dependencies = [
367 469
368[[package]] 470[[package]]
369name = "rmp-serde" 471name = "rmp-serde"
370version = "0.13.7" 472version = "0.15.5"
371source = "registry+https://github.com/rust-lang/crates.io-index" 473source = "registry+https://github.com/rust-lang/crates.io-index"
372checksum = "011e1d58446e9fa3af7cdc1fb91295b10621d3ac4cb3a85cc86385ee9ca50cd3" 474checksum = "723ecff9ad04f4ad92fe1c8ca6c20d2196d9286e9c60727c4cb5511629260e9d"
373dependencies = [ 475dependencies = [
374 "byteorder", 476 "byteorder",
375 "rmp", 477 "rmp",
@@ -377,42 +479,68 @@ dependencies = [
377] 479]
378 480
379[[package]] 481[[package]]
380name = "rmp-serde" 482name = "rustc-hash"
381version = "0.15.5" 483version = "1.1.0"
382source = "registry+https://github.com/rust-lang/crates.io-index" 484source = "registry+https://github.com/rust-lang/crates.io-index"
383checksum = "723ecff9ad04f4ad92fe1c8ca6c20d2196d9286e9c60727c4cb5511629260e9d" 485checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
486
487[[package]]
488name = "rustc_version"
489version = "0.4.1"
490source = "registry+https://github.com/rust-lang/crates.io-index"
491checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
384dependencies = [ 492dependencies = [
385 "byteorder", 493 "semver",
386 "rmp",
387 "serde",
388] 494]
389 495
390[[package]] 496[[package]]
391name = "scopeguard" 497name = "rustversion"
392version = "1.1.0" 498version = "1.0.22"
499source = "registry+https://github.com/rust-lang/crates.io-index"
500checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
501
502[[package]]
503name = "ryu"
504version = "1.0.20"
393source = "registry+https://github.com/rust-lang/crates.io-index" 505source = "registry+https://github.com/rust-lang/crates.io-index"
394checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 506checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
395 507
396[[package]] 508[[package]]
397name = "seahash" 509name = "seahash"
398version = "3.0.7" 510version = "4.1.0"
399source = "registry+https://github.com/rust-lang/crates.io-index" 511source = "registry+https://github.com/rust-lang/crates.io-index"
400checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" 512checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
513
514[[package]]
515name = "semver"
516version = "1.0.27"
517source = "registry+https://github.com/rust-lang/crates.io-index"
518checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
401 519
402[[package]] 520[[package]]
403name = "serde" 521name = "serde"
404version = "1.0.139" 522version = "1.0.228"
523source = "registry+https://github.com/rust-lang/crates.io-index"
524checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
525dependencies = [
526 "serde_core",
527 "serde_derive",
528]
529
530[[package]]
531name = "serde_core"
532version = "1.0.228"
405source = "registry+https://github.com/rust-lang/crates.io-index" 533source = "registry+https://github.com/rust-lang/crates.io-index"
406checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" 534checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
407dependencies = [ 535dependencies = [
408 "serde_derive", 536 "serde_derive",
409] 537]
410 538
411[[package]] 539[[package]]
412name = "serde_derive" 540name = "serde_derive"
413version = "1.0.139" 541version = "1.0.228"
414source = "registry+https://github.com/rust-lang/crates.io-index" 542source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" 543checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
416dependencies = [ 544dependencies = [
417 "proc-macro2", 545 "proc-macro2",
418 "quote", 546 "quote",
@@ -420,16 +548,35 @@ dependencies = [
420] 548]
421 549
422[[package]] 550[[package]]
551name = "serde_json"
552version = "1.0.145"
553source = "registry+https://github.com/rust-lang/crates.io-index"
554checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
555dependencies = [
556 "itoa",
557 "memchr",
558 "ryu",
559 "serde",
560 "serde_core",
561]
562
563[[package]]
423name = "smallvec" 564name = "smallvec"
424version = "1.9.0" 565version = "1.15.1"
425source = "registry+https://github.com/rust-lang/crates.io-index" 566source = "registry+https://github.com/rust-lang/crates.io-index"
426checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" 567checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
568
569[[package]]
570name = "stable_deref_trait"
571version = "1.2.1"
572source = "registry+https://github.com/rust-lang/crates.io-index"
573checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
427 574
428[[package]] 575[[package]]
429name = "syn" 576name = "syn"
430version = "1.0.98" 577version = "2.0.110"
431source = "registry+https://github.com/rust-lang/crates.io-index" 578source = "registry+https://github.com/rust-lang/crates.io-index"
432checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" 579checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
433dependencies = [ 580dependencies = [
434 "proc-macro2", 581 "proc-macro2",
435 "quote", 582 "quote",
@@ -437,120 +584,161 @@ dependencies = [
437] 584]
438 585
439[[package]] 586[[package]]
587name = "synstructure"
588version = "0.13.2"
589source = "registry+https://github.com/rust-lang/crates.io-index"
590checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
591dependencies = [
592 "proc-macro2",
593 "quote",
594 "syn",
595]
596
597[[package]]
440name = "target-lexicon" 598name = "target-lexicon"
441version = "0.12.4" 599version = "0.12.16"
442source = "registry+https://github.com/rust-lang/crates.io-index" 600source = "registry+https://github.com/rust-lang/crates.io-index"
443checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" 601checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
444 602
445[[package]] 603[[package]]
446name = "tinyvec" 604name = "thiserror"
447version = "1.6.0" 605version = "1.0.69"
448source = "registry+https://github.com/rust-lang/crates.io-index" 606source = "registry+https://github.com/rust-lang/crates.io-index"
449checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 607checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
450dependencies = [ 608dependencies = [
451 "tinyvec_macros", 609 "thiserror-impl",
452] 610]
453 611
454[[package]] 612[[package]]
455name = "tinyvec_macros" 613name = "thiserror-impl"
456version = "0.1.0" 614version = "1.0.69"
457source = "registry+https://github.com/rust-lang/crates.io-index" 615source = "registry+https://github.com/rust-lang/crates.io-index"
458checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 616checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
617dependencies = [
618 "proc-macro2",
619 "quote",
620 "syn",
621]
459 622
460[[package]] 623[[package]]
461name = "twoway" 624name = "tinystr"
462version = "0.2.2" 625version = "0.8.2"
463source = "registry+https://github.com/rust-lang/crates.io-index" 626source = "registry+https://github.com/rust-lang/crates.io-index"
464checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47" 627checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"
465dependencies = [ 628dependencies = [
466 "memchr", 629 "displaydoc",
467 "unchecked-index", 630 "zerovec",
468] 631]
469 632
470[[package]] 633[[package]]
471name = "unchecked-index" 634name = "unicode-ident"
472version = "0.2.2" 635version = "1.0.22"
473source = "registry+https://github.com/rust-lang/crates.io-index" 636source = "registry+https://github.com/rust-lang/crates.io-index"
474checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c" 637checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
475 638
476[[package]] 639[[package]]
477name = "unicode-bidi" 640name = "unindent"
478version = "0.3.8" 641version = "0.2.4"
479source = "registry+https://github.com/rust-lang/crates.io-index" 642source = "registry+https://github.com/rust-lang/crates.io-index"
480checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" 643checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
481 644
482[[package]] 645[[package]]
483name = "unicode-ident" 646name = "url"
484version = "1.0.2" 647version = "2.5.7"
485source = "registry+https://github.com/rust-lang/crates.io-index" 648source = "registry+https://github.com/rust-lang/crates.io-index"
486checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" 649checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b"
650dependencies = [
651 "form_urlencoded",
652 "idna",
653 "percent-encoding",
654 "serde",
655]
487 656
488[[package]] 657[[package]]
489name = "unicode-normalization" 658name = "utf8_iter"
490version = "0.1.21" 659version = "1.0.4"
491source = "registry+https://github.com/rust-lang/crates.io-index" 660source = "registry+https://github.com/rust-lang/crates.io-index"
492checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" 661checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
493dependencies = [
494 "tinyvec",
495]
496 662
497[[package]] 663[[package]]
498name = "unindent" 664name = "writeable"
499version = "0.1.9" 665version = "0.6.2"
500source = "registry+https://github.com/rust-lang/crates.io-index" 666source = "registry+https://github.com/rust-lang/crates.io-index"
501checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" 667checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
502 668
503[[package]] 669[[package]]
504name = "url" 670name = "yoke"
505version = "2.2.2" 671version = "0.8.1"
506source = "registry+https://github.com/rust-lang/crates.io-index" 672source = "registry+https://github.com/rust-lang/crates.io-index"
507checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" 673checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
508dependencies = [ 674dependencies = [
509 "form_urlencoded", 675 "stable_deref_trait",
510 "idna", 676 "yoke-derive",
511 "matches", 677 "zerofrom",
512 "percent-encoding",
513] 678]
514 679
515[[package]] 680[[package]]
516name = "windows-sys" 681name = "yoke-derive"
517version = "0.36.1" 682version = "0.8.1"
518source = "registry+https://github.com/rust-lang/crates.io-index" 683source = "registry+https://github.com/rust-lang/crates.io-index"
519checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" 684checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
520dependencies = [ 685dependencies = [
521 "windows_aarch64_msvc", 686 "proc-macro2",
522 "windows_i686_gnu", 687 "quote",
523 "windows_i686_msvc", 688 "syn",
524 "windows_x86_64_gnu", 689 "synstructure",
525 "windows_x86_64_msvc",
526] 690]
527 691
528[[package]] 692[[package]]
529name = "windows_aarch64_msvc" 693name = "zerofrom"
530version = "0.36.1" 694version = "0.1.6"
531source = "registry+https://github.com/rust-lang/crates.io-index" 695source = "registry+https://github.com/rust-lang/crates.io-index"
532checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" 696checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5"
697dependencies = [
698 "zerofrom-derive",
699]
533 700
534[[package]] 701[[package]]
535name = "windows_i686_gnu" 702name = "zerofrom-derive"
536version = "0.36.1" 703version = "0.1.6"
537source = "registry+https://github.com/rust-lang/crates.io-index" 704source = "registry+https://github.com/rust-lang/crates.io-index"
538checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" 705checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
706dependencies = [
707 "proc-macro2",
708 "quote",
709 "syn",
710 "synstructure",
711]
539 712
540[[package]] 713[[package]]
541name = "windows_i686_msvc" 714name = "zerotrie"
542version = "0.36.1" 715version = "0.2.3"
543source = "registry+https://github.com/rust-lang/crates.io-index" 716source = "registry+https://github.com/rust-lang/crates.io-index"
544checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" 717checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"
718dependencies = [
719 "displaydoc",
720 "yoke",
721 "zerofrom",
722]
545 723
546[[package]] 724[[package]]
547name = "windows_x86_64_gnu" 725name = "zerovec"
548version = "0.36.1" 726version = "0.11.5"
549source = "registry+https://github.com/rust-lang/crates.io-index" 727source = "registry+https://github.com/rust-lang/crates.io-index"
550checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" 728checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"
729dependencies = [
730 "yoke",
731 "zerofrom",
732 "zerovec-derive",
733]
551 734
552[[package]] 735[[package]]
553name = "windows_x86_64_msvc" 736name = "zerovec-derive"
554version = "0.36.1" 737version = "0.11.2"
555source = "registry+https://github.com/rust-lang/crates.io-index" 738source = "registry+https://github.com/rust-lang/crates.io-index"
556checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" 739checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
740dependencies = [
741 "proc-macro2",
742 "quote",
743 "syn",
744]
diff --git a/Cargo.toml b/Cargo.toml
index dc2f5f9..e90e35f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,8 +1,8 @@
1[package] 1[package]
2publish = false 2publish = false
3name = "adblock" 3name = "adblock"
4version = "0.6.0" 4version = "0.7.0"
5edition = "2018" 5edition = "2021"
6authors = ["Árni Dagur <arni@dagur.eu>"] 6authors = ["Árni Dagur <arni@dagur.eu>"]
7license = "MIT OR Apache-2.0" 7license = "MIT OR Apache-2.0"
8readme = "README.md" 8readme = "README.md"
@@ -13,9 +13,12 @@ repository = "https://github.com/ArniDagur/python-adblock"
13debug = true 13debug = true
14 14
15[dependencies] 15[dependencies]
16adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } 16adblock = { version = "0.11.1", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] }
17pyo3 = { version = "0.16", features = ["abi3-py37", "extension-module"] } 17pyo3 = { version = "0.22", features = ["abi3-py38", "extension-module"] }
18 18
19[lib] 19[lib]
20name = "adblock" 20name = "adblock"
21crate-type = ["rlib", "cdylib"] 21crate-type = ["rlib", "cdylib"]
22
23[[tool.maturin.python-packages]]
24name = "adblock"
diff --git a/pyproject.toml b/pyproject.toml
index 564e100..24448ce 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
1[project] 1[project]
2name = "adblock" 2name = "adblock"
3version = "0.6.0" 3version = "0.7.0"
4description = "Brave's adblocking in Python" 4description = "Brave's adblocking in Python"
5requires-python = ">=3.7" 5requires-python = ">=3.7"
6authors = [{ name = "Árni Dagur", email = "arni@dagur.eu" }] 6authors = [{ name = "Árni Dagur", email = "arni@dagur.eu" }]
@@ -13,7 +13,7 @@ classifiers = [
13 13
14[tool.poetry] 14[tool.poetry]
15name = "adblock" 15name = "adblock"
16version = "0.6.0" 16version = "0.7.0"
17description = "Brave's adblocking in Python" 17description = "Brave's adblocking in Python"
18authors = ["Árni Dagur <arni@dagur.eu>"] 18authors = ["Árni Dagur <arni@dagur.eu>"]
19 19
diff --git a/src/lib.rs b/src/lib.rs
index e8797d2..7aa2ade 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,21 +12,18 @@
12)] 12)]
13 13
14use adblock::blocker::BlockerResult as RustBlockerResult; 14use adblock::blocker::BlockerResult as RustBlockerResult;
15use adblock::blocker::{BlockerError as RustBlockerError, Redirection};
16use adblock::cosmetic_filter_cache::UrlSpecificResources as RustUrlSpecificResources; 15use adblock::cosmetic_filter_cache::UrlSpecificResources as RustUrlSpecificResources;
17use adblock::engine::Engine as RustEngine; 16use adblock::engine::Engine as RustEngine;
18use adblock::lists::FilterSet as RustFilterSet; 17use adblock::lists::FilterSet as RustFilterSet;
19use adblock::lists::{FilterFormat, ParseOptions, RuleTypes}; 18use adblock::lists::{FilterFormat, ParseOptions, RuleTypes};
19use adblock::request::Request;
20use pyo3::create_exception; 20use pyo3::create_exception;
21use pyo3::exceptions::PyException; 21use pyo3::exceptions::PyException;
22use pyo3::prelude::*; 22use pyo3::prelude::*;
23use pyo3::types::PyBytes; 23use pyo3::types::PyBytes;
24use pyo3::PyErr; 24use pyo3::PyErr;
25 25
26use adblock::resources::{ 26use adblock::resources::{MimeType, PermissionMask, Resource, ResourceType};
27 AddResourceError as RustAddResourceError, MimeType, Resource, ResourceType,
28};
29use std::collections::HashMap;
30use std::collections::HashSet; 27use std::collections::HashSet;
31use std::error::Error; 28use std::error::Error;
32use std::fmt::{self, Display}; 29use std::fmt::{self, Display};
@@ -35,39 +32,39 @@ use std::io::{Read, Write};
35 32
36/// Brave's adblocking library in Python! 33/// Brave's adblocking library in Python!
37#[pymodule] 34#[pymodule]
38fn adblock(py: Python<'_>, m: &PyModule) -> PyResult<()> { 35fn adblock_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
39 m.add("__version__", env!("CARGO_PKG_VERSION"))?; 36 m.add("__version__", env!("CARGO_PKG_VERSION"))?;
40 m.add_class::<Engine>()?; 37 m.add_class::<Engine>()?;
41 m.add_class::<FilterSet>()?; 38 m.add_class::<FilterSet>()?;
42 m.add_class::<BlockerResult>()?; 39 m.add_class::<BlockerResult>()?;
43 m.add_class::<UrlSpecificResources>()?; 40 m.add_class::<UrlSpecificResources>()?;
44 m.add("AdblockException", py.get_type::<AdblockException>())?; 41 m.add("AdblockException", m.py().get_type_bound::<AdblockException>())?;
45 m.add("BlockerException", py.get_type::<BlockerException>())?; 42 m.add("BlockerException", m.py().get_type_bound::<BlockerException>())?;
46 m.add("SerializationError", py.get_type::<SerializationError>())?; 43 m.add("SerializationError", m.py().get_type_bound::<SerializationError>())?;
47 m.add( 44 m.add(
48 "DeserializationError", 45 "DeserializationError",
49 py.get_type::<DeserializationError>(), 46 m.py().get_type_bound::<DeserializationError>(),
50 )?; 47 )?;
51 m.add( 48 m.add(
52 "OptimizedFilterExistence", 49 "OptimizedFilterExistence",
53 py.get_type::<OptimizedFilterExistence>(), 50 m.py().get_type_bound::<OptimizedFilterExistence>(),
54 )?; 51 )?;
55 m.add( 52 m.add(
56 "BadFilterAddUnsupported", 53 "BadFilterAddUnsupported",
57 py.get_type::<BadFilterAddUnsupported>(), 54 m.py().get_type_bound::<BadFilterAddUnsupported>(),
58 )?; 55 )?;
59 m.add("FilterExists", py.get_type::<FilterExists>())?; 56 m.add("FilterExists", m.py().get_type_bound::<FilterExists>())?;
60 m.add( 57 m.add(
61 "AddResourceException", 58 "AddResourceException",
62 py.get_type::<AddResourceException>(), 59 m.py().get_type_bound::<AddResourceException>(),
63 )?; 60 )?;
64 m.add( 61 m.add(
65 "InvalidBase64ContentError", 62 "InvalidBase64ContentError",
66 py.get_type::<InvalidBase64ContentError>(), 63 m.py().get_type_bound::<InvalidBase64ContentError>(),
67 )?; 64 )?;
68 m.add( 65 m.add(
69 "InvalidUtf8ContentError", 66 "InvalidUtf8ContentError",
70 py.get_type::<InvalidUtf8ContentError>(), 67 m.py().get_type_bound::<InvalidUtf8ContentError>(),
71 )?; 68 )?;
72 Ok(()) 69 Ok(())
73} 70}
@@ -94,14 +91,11 @@ pub struct BlockerResult {
94 /// 91 ///
95 /// [1]: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#redirect 92 /// [1]: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#redirect
96 #[pyo3(get)] 93 #[pyo3(get)]
97 pub redirect_type: Option<String>,
98 /// Exception is not `None` when the blocker matched on an exception rule.
99 /// Effectively this means that there was a match, but the request should
100 /// not be blocked. It is a non-empty string if the blocker was initialized
101 /// from a list of rules with debugging enabled, otherwise the original
102 /// string representation is discarded to reduce memory use.
103 #[pyo3(get)]
104 pub redirect: Option<String>, 94 pub redirect: Option<String>,
95 /// `removeparam` may remove URL parameters. If the original request URL was
96 /// modified at all, the new version will be here.
97 #[pyo3(get)]
98 pub rewritten_url: Option<String>,
105 /// Exception is not `None` when the blocker matched on an exception rule. 99 /// Exception is not `None` when the blocker matched on an exception rule.
106 /// Effectively this means that there was a match, but the request should 100 /// Effectively this means that there was a match, but the request should
107 /// not be blocked. It is a non-empty string if the blocker was initialized 101 /// not be blocked. It is a non-empty string if the blocker was initialized
@@ -114,32 +108,17 @@ pub struct BlockerResult {
114 /// a match, it is not `None`. 108 /// a match, it is not `None`.
115 #[pyo3(get)] 109 #[pyo3(get)]
116 pub filter: Option<String>, 110 pub filter: Option<String>,
117 /// The `error` field is only used to signal that there was an error in
118 /// parsing the provided URLs when using the simpler
119 /// `check_network_urls` method.
120 #[pyo3(get)]
121 pub error: Option<String>,
122} 111}
123 112
124impl From<RustBlockerResult> for BlockerResult { 113impl From<RustBlockerResult> for BlockerResult {
125 fn from(br: RustBlockerResult) -> Self { 114 fn from(br: RustBlockerResult) -> Self {
126 let (redirect, redirect_type) = if let Some(resource) = br.redirect {
127 match resource {
128 Redirection::Resource(resource) => (Some(resource), Some("resource".to_string())),
129 Redirection::Url(url) => (Some(url), Some("url".to_string())),
130 }
131 } else {
132 (None, None)
133 };
134
135 Self { 115 Self {
136 matched: br.matched, 116 matched: br.matched,
137 important: br.important, 117 important: br.important,
118 redirect: br.redirect,
119 rewritten_url: br.rewritten_url,
138 exception: br.exception, 120 exception: br.exception,
139 filter: br.filter, 121 filter: br.filter,
140 error: br.error,
141 redirect_type,
142 redirect,
143 } 122 }
144 } 123 }
145} 124}
@@ -148,13 +127,13 @@ impl From<RustBlockerResult> for BlockerResult {
148impl BlockerResult { 127impl BlockerResult {
149 fn __repr__(&self) -> PyResult<String> { 128 fn __repr__(&self) -> PyResult<String> {
150 Ok(format!( 129 Ok(format!(
151 "BlockerResult(matched={}, important={}, redirect={}, exception={}, filter={}, error={})", 130 "BlockerResult(matched={}, important={}, redirect={}, rewritten_url={}, exception={}, filter={})",
152 self.matched.diy_python_repr(), 131 self.matched.diy_python_repr(),
153 self.important.diy_python_repr(), 132 self.important.diy_python_repr(),
154 self.redirect.diy_python_repr(), 133 self.redirect.diy_python_repr(),
134 self.rewritten_url.diy_python_repr(),
155 self.exception.diy_python_repr(), 135 self.exception.diy_python_repr(),
156 self.filter.diy_python_repr(), 136 self.filter.diy_python_repr(),
157 self.error.diy_python_repr(),
158 )) 137 ))
159 } 138 }
160} 139}
@@ -214,17 +193,6 @@ impl From<BlockerError> for PyErr {
214 } 193 }
215} 194}
216 195
217impl From<RustBlockerError> for BlockerError {
218 fn from(err: RustBlockerError) -> Self {
219 match err {
220 RustBlockerError::SerializationError => Self::SerializationError,
221 RustBlockerError::DeserializationError => Self::DeserializationError,
222 RustBlockerError::OptimizedFilterExistence => Self::OptimizedFilterExistence,
223 RustBlockerError::BadFilterAddUnsupported => Self::BadFilterAddUnsupported,
224 RustBlockerError::FilterExists => Self::FilterExists,
225 }
226 }
227}
228 196
229fn filter_format_from_string(filter_format: &str) -> PyResult<FilterFormat> { 197fn filter_format_from_string(filter_format: &str) -> PyResult<FilterFormat> {
230 match filter_format { 198 match filter_format {
@@ -252,7 +220,6 @@ fn rule_types_from_string(rule_types: &str) -> PyResult<RuleTypes> {
252/// created. FilterSet allows assembling a compound list from multiple 220/// created. FilterSet allows assembling a compound list from multiple
253/// different sources before compiling the rules into an Engine. 221/// different sources before compiling the rules into an Engine.
254#[pyclass] 222#[pyclass]
255#[pyo3(text_signature = "($self, debug)")]
256#[derive(Clone)] 223#[derive(Clone)]
257pub struct FilterSet { 224pub struct FilterSet {
258 filter_set: RustFilterSet, 225 filter_set: RustFilterSet,
@@ -266,7 +233,7 @@ impl FilterSet {
266 /// the more compact internal representation. If enabled, this information 233 /// the more compact internal representation. If enabled, this information
267 /// will be passed to the corresponding Engine. 234 /// will be passed to the corresponding Engine.
268 #[new] 235 #[new]
269 #[args(debug = false)] 236 #[pyo3(signature = (debug = false))]
270 pub fn new(debug: bool) -> Self { 237 pub fn new(debug: bool) -> Self {
271 Self { 238 Self {
272 filter_set: RustFilterSet::new(debug), 239 filter_set: RustFilterSet::new(debug),
@@ -279,18 +246,11 @@ impl FilterSet {
279 /// 246 ///
280 /// The format is a string containing either "standard" (ABP/uBO-style) 247 /// The format is a string containing either "standard" (ABP/uBO-style)
281 /// or "hosts". 248 /// or "hosts".
282 #[pyo3(text_signature = "($self, filter_list, format, include_redirect_urls, rule_types)")] 249 #[pyo3(signature = (filter_list, format = "standard", rule_types = "all"))]
283 #[args(
284 filter_list,
285 format = "\"standard\"",
286 include_redirect_urls = "false",
287 rule_types = "\"all\""
288 )]
289 pub fn add_filter_list( 250 pub fn add_filter_list(
290 &mut self, 251 &mut self,
291 filter_list: &str, 252 filter_list: &str,
292 format: &str, 253 format: &str,
293 include_redirect_urls: bool,
294 rule_types: &str, 254 rule_types: &str,
295 ) -> PyResult<()> { 255 ) -> PyResult<()> {
296 let filter_format = filter_format_from_string(format)?; 256 let filter_format = filter_format_from_string(format)?;
@@ -299,8 +259,8 @@ impl FilterSet {
299 filter_list, 259 filter_list,
300 ParseOptions { 260 ParseOptions {
301 format: filter_format, 261 format: filter_format,
302 include_redirect_urls,
303 rule_types, 262 rule_types,
263 permissions: PermissionMask::default(),
304 }, 264 },
305 ); 265 );
306 Ok(()) 266 Ok(())
@@ -311,18 +271,11 @@ impl FilterSet {
311 /// 271 ///
312 /// The format is a string containing either "standard" (ABP/uBO-style) 272 /// The format is a string containing either "standard" (ABP/uBO-style)
313 /// or "hosts". 273 /// or "hosts".
314 #[pyo3(text_signature = "($self, filters, format, include_redirect_urls, rule_types)")] 274 #[pyo3(signature = (filters, format = "standard", rule_types = "all"))]
315 #[args(
316 filters,
317 format = "\"standard\"",
318 include_redirect_urls = "false",
319 rule_types = "\"all\""
320 )]
321 pub fn add_filters( 275 pub fn add_filters(
322 &mut self, 276 &mut self,
323 filters: Vec<String>, 277 filters: Vec<String>,
324 format: &str, 278 format: &str,
325 include_redirect_urls: bool,
326 rule_types: &str, 279 rule_types: &str,
327 ) -> PyResult<()> { 280 ) -> PyResult<()> {
328 let filter_format = filter_format_from_string(format)?; 281 let filter_format = filter_format_from_string(format)?;
@@ -331,8 +284,8 @@ impl FilterSet {
331 &filters, 284 &filters,
332 ParseOptions { 285 ParseOptions {
333 format: filter_format, 286 format: filter_format,
334 include_redirect_urls,
335 rule_types, 287 rule_types,
288 permissions: PermissionMask::default(),
336 }, 289 },
337 ); 290 );
338 Ok(()) 291 Ok(())
@@ -351,10 +304,9 @@ pub struct UrlSpecificResources {
351 /// styled as `{ display: none !important; }`. 304 /// styled as `{ display: none !important; }`.
352 #[pyo3(get)] 305 #[pyo3(get)]
353 pub hide_selectors: HashSet<String>, 306 pub hide_selectors: HashSet<String>,
354 /// A map of CSS selectors on the page to respective non-hide style rules, 307 /// Set of JSON-encoded procedural filters or filters with an action.
355 /// i.e. any required styles other than `display: none`.
356 #[pyo3(get)] 308 #[pyo3(get)]
357 pub style_selectors: HashMap<String, Vec<String>>, 309 pub procedural_actions: HashSet<String>,
358 /// A set of any class or id CSS selectors that should not have generic 310 /// A set of any class or id CSS selectors that should not have generic
359 /// rules applied. 311 /// rules applied.
360 // In practice, these should be passed to `class_id_stylesheet` and not 312 // In practice, these should be passed to `class_id_stylesheet` and not
@@ -376,7 +328,7 @@ impl From<RustUrlSpecificResources> for UrlSpecificResources {
376 fn from(r: RustUrlSpecificResources) -> Self { 328 fn from(r: RustUrlSpecificResources) -> Self {
377 Self { 329 Self {
378 hide_selectors: r.hide_selectors, 330 hide_selectors: r.hide_selectors,
379 style_selectors: r.style_selectors, 331 procedural_actions: r.procedural_actions,
380 exceptions: r.exceptions, 332 exceptions: r.exceptions,
381 injected_script: r.injected_script, 333 injected_script: r.injected_script,
382 generichide: r.generichide, 334 generichide: r.generichide,
@@ -388,9 +340,9 @@ impl From<RustUrlSpecificResources> for UrlSpecificResources {
388impl UrlSpecificResources { 340impl UrlSpecificResources {
389 fn __repr__(&self) -> PyResult<String> { 341 fn __repr__(&self) -> PyResult<String> {
390 Ok(format!( 342 Ok(format!(
391 "UrlSpecificResources<{} hide selectors, {} style selectors, {} exceptions, injected_javascript={}, generichide={}>", 343 "UrlSpecificResources<{} hide selectors, {} procedural actions, {} exceptions, injected_javascript={}, generichide={}>",
392 self.hide_selectors.len(), 344 self.hide_selectors.len(),
393 self.style_selectors.len(), 345 self.procedural_actions.len(),
394 self.exceptions.len(), 346 self.exceptions.len(),
395 self.injected_script.diy_python_repr(), 347 self.injected_script.diy_python_repr(),
396 self.generichide.diy_python_repr(), 348 self.generichide.diy_python_repr(),
@@ -418,7 +370,6 @@ impl UrlSpecificResources {
418/// 370///
419/// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType 371/// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType
420#[pyclass] 372#[pyclass]
421#[pyo3(text_signature = "($self, filter_set, optimize)")]
422pub struct Engine { 373pub struct Engine {
423 engine: RustEngine, 374 engine: RustEngine,
424 optimize: bool, 375 optimize: bool,
@@ -428,7 +379,7 @@ pub struct Engine {
428impl Engine { 379impl Engine {
429 /// Create a new adblocking engine 380 /// Create a new adblocking engine
430 #[new] 381 #[new]
431 #[args(filter_set, optimize = true)] 382 #[pyo3(signature = (filter_set, optimize = true))]
432 pub fn new(filter_set: FilterSet, optimize: bool) -> Self { 383 pub fn new(filter_set: FilterSet, optimize: bool) -> Self {
433 let engine = RustEngine::from_filter_set(filter_set.filter_set, optimize); 384 let engine = RustEngine::from_filter_set(filter_set.filter_set, optimize);
434 Self { engine, optimize } 385 Self { engine, optimize }
@@ -442,17 +393,26 @@ impl Engine {
442 /// * `url` - The URL of the request to check 393 /// * `url` - The URL of the request to check
443 /// * `source_url` - The URL from where the request is made 394 /// * `source_url` - The URL from where the request is made
444 /// * `request_type` - The resource type that the request points to 395 /// * `request_type` - The resource type that the request points to
445 #[pyo3(text_signature = "($self, url, source_url, request_type)")]
446 pub fn check_network_urls( 396 pub fn check_network_urls(
447 &self, 397 &self,
448 url: &str, 398 url: &str,
449 source_url: &str, 399 source_url: &str,
450 request_type: &str, 400 request_type: &str,
451 ) -> BlockerResult { 401 ) -> BlockerResult {
452 let blocker_result = self 402 match Request::new(url, source_url, request_type) {
453 .engine 403 Ok(request) => {
454 .check_network_urls(url, source_url, request_type); 404 let blocker_result = self.engine.check_network_request(&request);
455 blocker_result.into() 405 blocker_result.into()
406 }
407 Err(_) => BlockerResult {
408 matched: false,
409 important: false,
410 redirect: None,
411 rewritten_url: None,
412 exception: None,
413 filter: None,
414 }
415 }
456 } 416 }
457 417
458 /// Check if a request should be blocked based on the given parameters. 418 /// Check if a request should be blocked based on the given parameters.
@@ -465,9 +425,7 @@ impl Engine {
465 /// * `third_party_request` - Is the given request to a third-party? Here, 425 /// * `third_party_request` - Is the given request to a third-party? Here,
466 /// `None` can be given and the engine will figure it out based on the 426 /// `None` can be given and the engine will figure it out based on the
467 /// `hostname` and `source_hostname`. 427 /// `hostname` and `source_hostname`.
468 #[pyo3( 428 #[pyo3(signature = (url, hostname, source_hostname, request_type, third_party_request = None))]
469 text_signature = "($self, url, hostname, source_hostname, requsest_type, third_party_request)"
470 )]
471 pub fn check_network_urls_with_hostnames( 429 pub fn check_network_urls_with_hostnames(
472 &self, 430 &self,
473 url: &str, 431 url: &str,
@@ -476,13 +434,11 @@ impl Engine {
476 request_type: &str, 434 request_type: &str,
477 third_party_request: Option<bool>, 435 third_party_request: Option<bool>,
478 ) -> BlockerResult { 436 ) -> BlockerResult {
479 let blocker_result = self.engine.check_network_urls_with_hostnames( 437 let third_party = third_party_request.unwrap_or_else(|| {
480 url, 438 hostname != source_hostname
481 hostname, 439 });
482 source_hostname, 440 let request = Request::preparsed(url, hostname, source_hostname, request_type, third_party);
483 request_type, 441 let blocker_result = self.engine.check_network_request(&request);
484 third_party_request,
485 );
486 blocker_result.into() 442 blocker_result.into()
487 } 443 }
488 444
@@ -499,10 +455,7 @@ impl Engine {
499 /// * `previously_matched_rule` - Return a match as long as there are no 455 /// * `previously_matched_rule` - Return a match as long as there are no
500 /// exceptions 456 /// exceptions
501 /// * `force_check_exceptions` - Check exceptions even if no other rule matches 457 /// * `force_check_exceptions` - Check exceptions even if no other rule matches
502 #[pyo3( 458 #[pyo3(signature = (url, hostname, source_hostname, request_type, third_party_request = None, previously_matched_rule = false, force_check_exceptions = false))]
503 text_signature = "($self, url, hostname, source_hostname, request_type, \
504 third_party_request, previously_matched_rule, force_check_exceptions)"
505 )]
506 #[allow(clippy::too_many_arguments)] 459 #[allow(clippy::too_many_arguments)]
507 pub fn check_network_urls_with_hostnames_subset( 460 pub fn check_network_urls_with_hostnames_subset(
508 &self, 461 &self,
@@ -514,12 +467,12 @@ impl Engine {
514 previously_matched_rule: bool, 467 previously_matched_rule: bool,
515 force_check_exceptions: bool, 468 force_check_exceptions: bool,
516 ) -> BlockerResult { 469 ) -> BlockerResult {
517 let blocker_result = self.engine.check_network_urls_with_hostnames_subset( 470 let third_party = third_party_request.unwrap_or_else(|| {
518 url, 471 hostname != source_hostname
519 hostname, 472 });
520 source_hostname, 473 let request = Request::preparsed(url, hostname, source_hostname, request_type, third_party);
521 request_type, 474 let blocker_result = self.engine.check_network_request_subset(
522 third_party_request, 475 &request,
523 previously_matched_rule, 476 previously_matched_rule,
524 force_check_exceptions, 477 force_check_exceptions,
525 ); 478 );
@@ -534,7 +487,7 @@ impl Engine {
534 /// Use `"template"` if wanting to specify a template resource type. 487 /// Use `"template"` if wanting to specify a template resource type.
535 /// * `content`: The resource data, encoded using standard base64 configuration 488 /// * `content`: The resource data, encoded using standard base64 configuration
536 /// * `aliases`: List of aliases for the resource 489 /// * `aliases`: List of aliases for the resource
537 #[pyo3(text_signature = "($self, name, content_type, content, aliases)")] 490 #[pyo3(signature = (name, content_type, content, aliases = None))]
538 pub fn add_resource( 491 pub fn add_resource(
539 &mut self, 492 &mut self,
540 name: &str, 493 name: &str,
@@ -542,7 +495,7 @@ impl Engine {
542 content: &str, 495 content: &str,
543 aliases: Option<Vec<String>>, 496 aliases: Option<Vec<String>>,
544 ) -> PyResult<()> { 497 ) -> PyResult<()> {
545 let result = self.engine.add_resource(Resource { 498 let resource = Resource {
546 name: name.to_string(), 499 name: name.to_string(),
547 aliases: aliases.unwrap_or_default(), 500 aliases: aliases.unwrap_or_default(),
548 kind: match content_type { 501 kind: match content_type {
@@ -552,47 +505,27 @@ impl Engine {
552 ))), 505 ))),
553 }, 506 },
554 content: content.to_string(), 507 content: content.to_string(),
555 }); 508 dependencies: Vec::new(),
509 permission: PermissionMask::default(),
510 };
556 511
557 match result { 512 self.engine.use_resources(std::iter::once(resource));
558 Ok(_) => Ok(()), 513 Ok(())
559 Err(err) => match err {
560 RustAddResourceError::InvalidBase64Content => Err(
561 InvalidBase64ContentError::new_err("invalid base64 content".to_string()),
562 ),
563 RustAddResourceError::InvalidUtf8Content => Err(InvalidUtf8ContentError::new_err(
564 "invalid utf content".to_string(),
565 )),
566 },
567 }
568 } 514 }
569 515
570 /// Serialize this blocking engine to bytes. They can then be deserialized 516 /// Serialize this blocking engine to bytes. They can then be deserialized
571 /// using `deserialize()` to get the same engine again. 517 /// using `deserialize()` to get the same engine again.
572 #[pyo3(text_signature = "($self)")] 518 pub fn serialize<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyBytes>> {
573 pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult<&'p PyBytes> { 519 let bytes = self.engine.serialize();
574 let bytes = self.serialize_inner()?; 520 let py_bytes = PyBytes::new_bound(py, &bytes);
575 let py_bytes = PyBytes::new(py, &bytes);
576 Ok(py_bytes) 521 Ok(py_bytes)
577 } 522 }
578 523
579 fn serialize_inner(&mut self) -> PyResult<Vec<u8>> {
580 let result = self.engine.serialize_raw();
581 match result {
582 Ok(x) => Ok(x),
583 Err(error) => {
584 let my_blocker_error: BlockerError = error.into();
585 Err(my_blocker_error.into())
586 }
587 }
588 }
589
590 /// Serialize this blocking engine to a file. The file can then be 524 /// Serialize this blocking engine to a file. The file can then be
591 /// deserialized using `deserialize_from_file()` to get the same engine 525 /// deserialized using `deserialize_from_file()` to get the same engine
592 /// again. 526 /// again.
593 #[pyo3(text_signature = "($self, file)")] 527 pub fn serialize_to_file(&self, file: &str) -> PyResult<()> {
594 pub fn serialize_to_file(&mut self, file: &str) -> PyResult<()> { 528 let data = self.engine.serialize();
595 let data = self.serialize_inner()?;
596 let mut fd = fs::OpenOptions::new() 529 let mut fd = fs::OpenOptions::new()
597 .create(true) 530 .create(true)
598 .truncate(true) 531 .truncate(true)
@@ -603,21 +536,14 @@ impl Engine {
603 } 536 }
604 537
605 /// Deserialize a blocking engine from bytes produced with `serialize()`. 538 /// Deserialize a blocking engine from bytes produced with `serialize()`.
606 #[pyo3(text_signature = "($self, serialized)")]
607 pub fn deserialize(&mut self, serialized: &[u8]) -> PyResult<()> { 539 pub fn deserialize(&mut self, serialized: &[u8]) -> PyResult<()> {
608 let result = self.engine.deserialize(serialized); 540 self.engine.deserialize(serialized).map_err(|_| {
609 match result { 541 DeserializationError::new_err("Failed to deserialize engine data")
610 Ok(_) => Ok(()), 542 })
611 Err(error) => {
612 let my_blocker_error: BlockerError = error.into();
613 Err(my_blocker_error.into())
614 }
615 }
616 } 543 }
617 544
618 /// Deserialize a blocking engine from file produced with 545 /// Deserialize a blocking engine from file produced with
619 /// `serialize_to_file()`. 546 /// `serialize_to_file()`.
620 #[pyo3(text_signature = "($self, file)")]
621 pub fn deserialize_from_file(&mut self, file: &str) -> PyResult<()> { 547 pub fn deserialize_from_file(&mut self, file: &str) -> PyResult<()> {
622 let mut fd = fs::File::open(file)?; 548 let mut fd = fs::File::open(file)?;
623 let mut data: Vec<u8> = Vec::new(); 549 let mut data: Vec<u8> = Vec::new();
@@ -626,18 +552,20 @@ impl Engine {
626 } 552 }
627 553
628 /// Checks if the given filter exists in the blocking engine. 554 /// Checks if the given filter exists in the blocking engine.
629 #[pyo3(text_signature = "($self, filter)")] 555 /// Note: This method has been removed in the latest version of adblock-rust.
630 pub fn filter_exists(&self, filter: &str) -> bool { 556 /// It will always return false.
631 self.engine.filter_exists(filter) 557 pub fn filter_exists(&self, _filter: &str) -> bool {
558 // This method no longer exists in the adblock-rust API
559 false
632 } 560 }
633 561
634 /// Sets this engine's tags to be _only_ the ones provided in tags. 562 /// Sets this engine's tags to be _only_ the ones provided in tags.
635 /// 563 ///
636 /// Tags can be used to cheaply enable or disable network rules with a 564 /// Tags can be used to cheaply enable or disable network rules with a
637 /// corresponding $tag option. 565 /// corresponding $tag option.
638 #[pyo3(text_signature = "($self, tags)")] 566 pub fn use_tags(&mut self, tags: Vec<String>) {
639 pub fn use_tags(&mut self, tags: Vec<&str>) { 567 let tag_refs: Vec<&str> = tags.iter().map(|s| s.as_str()).collect();
640 self.engine.use_tags(&tags); 568 self.engine.use_tags(&tag_refs);
641 } 569 }
642 570
643 /// Sets this engine's tags to additionally include the ones provided in 571 /// Sets this engine's tags to additionally include the ones provided in
@@ -645,9 +573,9 @@ impl Engine {
645 /// 573 ///
646 /// Tags can be used to cheaply enable or disable network rules with a 574 /// Tags can be used to cheaply enable or disable network rules with a
647 /// corresponding $tag option. 575 /// corresponding $tag option.
648 #[pyo3(text_signature = "($self, tags)")] 576 pub fn enable_tags(&mut self, tags: Vec<String>) {
649 pub fn enable_tags(&mut self, tags: Vec<&str>) { 577 let tag_refs: Vec<&str> = tags.iter().map(|s| s.as_str()).collect();
650 self.engine.enable_tags(&tags); 578 self.engine.enable_tags(&tag_refs);
651 } 579 }
652 580
653 /// Sets this engine's tags to no longer include the ones provided in 581 /// Sets this engine's tags to no longer include the ones provided in
@@ -655,16 +583,15 @@ impl Engine {
655 /// 583 ///
656 /// Tags can be used to cheaply enable or disable network rules with a 584 /// Tags can be used to cheaply enable or disable network rules with a
657 /// corresponding $tag option. 585 /// corresponding $tag option.
658 #[pyo3(text_signature = "($self, tags)")] 586 pub fn disable_tags(&mut self, tags: Vec<String>) {
659 pub fn disable_tags(&mut self, tags: Vec<&str>) { 587 let tag_refs: Vec<&str> = tags.iter().map(|s| s.as_str()).collect();
660 self.engine.disable_tags(&tags); 588 self.engine.disable_tags(&tag_refs);
661 } 589 }
662 590
663 /// Checks if a given tag exists in this engine. 591 /// Checks if a given tag exists in this engine.
664 /// 592 ///
665 /// Tags can be used to cheaply enable or disable network rules with a 593 /// Tags can be used to cheaply enable or disable network rules with a
666 /// corresponding $tag option. 594 /// corresponding $tag option.
667 #[pyo3(text_signature = "($self, tag)")]
668 pub fn tag_exists(&self, tag: &str) -> bool { 595 pub fn tag_exists(&self, tag: &str) -> bool {
669 self.engine.tag_exists(tag) 596 self.engine.tag_exists(tag)
670 } 597 }
@@ -673,7 +600,6 @@ impl Engine {
673 /// url. Once this has been called, all CSS ids and classes on a 600 /// url. Once this has been called, all CSS ids and classes on a
674 /// page should be passed to hidden_class_id_selectors to obtain any 601 /// page should be passed to hidden_class_id_selectors to obtain any
675 /// stylesheets consisting of generic rules. 602 /// stylesheets consisting of generic rules.
676 #[pyo3(text_signature = "($self, url)")]
677 pub fn url_cosmetic_resources(&self, url: &str) -> UrlSpecificResources { 603 pub fn url_cosmetic_resources(&self, url: &str) -> UrlSpecificResources {
678 self.engine.url_cosmetic_resources(url).into() 604 self.engine.url_cosmetic_resources(url).into()
679 } 605 }
@@ -685,7 +611,6 @@ impl Engine {
685 /// are not excepted. 611 /// are not excepted.
686 /// 612 ///
687 /// Exceptions should be passed directly from UrlSpecificResources. 613 /// Exceptions should be passed directly from UrlSpecificResources.
688 #[pyo3(text_signature = "($self, classes, ids, exceptions)")]
689 pub fn hidden_class_id_selectors( 614 pub fn hidden_class_id_selectors(
690 &self, 615 &self,
691 classes: Vec<String>, 616 classes: Vec<String>,