parsec-web 0.3.0__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.
Files changed (119) hide show
  1. parsec_web-0.3.0/Cargo.toml +14 -0
  2. parsec_web-0.3.0/LICENSE +201 -0
  3. parsec_web-0.3.0/NOTICE +70 -0
  4. parsec_web-0.3.0/PKG-INFO +289 -0
  5. parsec_web-0.3.0/README.md +262 -0
  6. parsec_web-0.3.0/bindings/python/Cargo.lock +631 -0
  7. parsec_web-0.3.0/bindings/python/Cargo.toml +46 -0
  8. parsec_web-0.3.0/bindings/python/LICENSE +201 -0
  9. parsec_web-0.3.0/bindings/python/NOTICE +70 -0
  10. parsec_web-0.3.0/bindings/python/README.md +262 -0
  11. parsec_web-0.3.0/bindings/python/bench.py +98 -0
  12. parsec_web-0.3.0/bindings/python/ci-requirements.in +2 -0
  13. parsec_web-0.3.0/bindings/python/ci-requirements.txt +121 -0
  14. parsec_web-0.3.0/bindings/python/parsec_html.pyi +435 -0
  15. parsec_web-0.3.0/bindings/python/src/js.rs +192 -0
  16. parsec_web-0.3.0/bindings/python/src/lib.rs +2021 -0
  17. parsec_web-0.3.0/bindings/python/src/units.rs +133 -0
  18. parsec_web-0.3.0/bindings/python/src/xml.rs +462 -0
  19. parsec_web-0.3.0/bindings/python/tests/test_encoding.py +203 -0
  20. parsec_web-0.3.0/bindings/python/tests/test_js.py +134 -0
  21. parsec_web-0.3.0/bindings/python/tests/test_parsec_html.py +546 -0
  22. parsec_web-0.3.0/bindings/python/tests/test_xml.py +172 -0
  23. parsec_web-0.3.0/crates/parsec/Cargo.toml +27 -0
  24. parsec_web-0.3.0/crates/parsec/LICENSE +201 -0
  25. parsec_web-0.3.0/crates/parsec/NOTICE +70 -0
  26. parsec_web-0.3.0/crates/parsec/README.md +587 -0
  27. parsec_web-0.3.0/crates/parsec/examples/hostile.rs +38 -0
  28. parsec_web-0.3.0/crates/parsec/examples/parallel.rs +32 -0
  29. parsec_web-0.3.0/crates/parsec/examples/parse.rs +19 -0
  30. parsec_web-0.3.0/crates/parsec/examples/select.rs +78 -0
  31. parsec_web-0.3.0/crates/parsec/examples/serialize.rs +21 -0
  32. parsec_web-0.3.0/crates/parsec/examples/tokenize.rs +41 -0
  33. parsec_web-0.3.0/crates/parsec/scripts/fetch-tree-tests.sh +15 -0
  34. parsec_web-0.3.0/crates/parsec/scripts/fetch-wpt-selectors.sh +33 -0
  35. parsec_web-0.3.0/crates/parsec/scripts/gen-entities.py +36 -0
  36. parsec_web-0.3.0/crates/parsec/scripts/gen-unicode.py +257 -0
  37. parsec_web-0.3.0/crates/parsec/scripts/wpt-selectors-cases.js +454 -0
  38. parsec_web-0.3.0/crates/parsec/src/css.rs +4032 -0
  39. parsec_web-0.3.0/crates/parsec/src/dom.rs +1280 -0
  40. parsec_web-0.3.0/crates/parsec/src/edit.rs +1235 -0
  41. parsec_web-0.3.0/crates/parsec/src/entities.rs +2239 -0
  42. parsec_web-0.3.0/crates/parsec/src/lib.rs +222 -0
  43. parsec_web-0.3.0/crates/parsec/src/pattern.rs +1518 -0
  44. parsec_web-0.3.0/crates/parsec/src/serialize.rs +1529 -0
  45. parsec_web-0.3.0/crates/parsec/src/shadow.rs +822 -0
  46. parsec_web-0.3.0/crates/parsec/src/tags.rs +232 -0
  47. parsec_web-0.3.0/crates/parsec/src/tokenizer.rs +2793 -0
  48. parsec_web-0.3.0/crates/parsec/src/tree.rs +4699 -0
  49. parsec_web-0.3.0/crates/parsec/src/unicode.rs +3177 -0
  50. parsec_web-0.3.0/crates/parsec-base/Cargo.toml +15 -0
  51. parsec_web-0.3.0/crates/parsec-base/LICENSE +201 -0
  52. parsec_web-0.3.0/crates/parsec-base/NOTICE +70 -0
  53. parsec_web-0.3.0/crates/parsec-base/README.md +587 -0
  54. parsec_web-0.3.0/crates/parsec-base/src/lib.rs +594 -0
  55. parsec_web-0.3.0/crates/parsec-base/src/render.rs +552 -0
  56. parsec_web-0.3.0/crates/parsec-encoding/Cargo.toml +26 -0
  57. parsec_web-0.3.0/crates/parsec-encoding/LICENSE +201 -0
  58. parsec_web-0.3.0/crates/parsec-encoding/NOTICE +70 -0
  59. parsec_web-0.3.0/crates/parsec-encoding/README.md +587 -0
  60. parsec_web-0.3.0/crates/parsec-encoding/src/lib.rs +405 -0
  61. parsec_web-0.3.0/crates/parsec-encoding/src/offsets.rs +279 -0
  62. parsec_web-0.3.0/crates/parsec-encoding/src/prescan.rs +351 -0
  63. parsec_web-0.3.0/crates/parsec-encoding/src/stream.rs +380 -0
  64. parsec_web-0.3.0/crates/parsec-js/Cargo.toml +26 -0
  65. parsec_web-0.3.0/crates/parsec-js/LICENSE +201 -0
  66. parsec_web-0.3.0/crates/parsec-js/NOTICE +70 -0
  67. parsec_web-0.3.0/crates/parsec-js/README.md +587 -0
  68. parsec_web-0.3.0/crates/parsec-js/examples/estree.rs +43 -0
  69. parsec_web-0.3.0/crates/parsec-js/scripts/compare-acorn.sh +90 -0
  70. parsec_web-0.3.0/crates/parsec-js/scripts/gen-estree-fixtures.sh +40 -0
  71. parsec_web-0.3.0/crates/parsec-js/scripts/gen-regexp-names.py +81 -0
  72. parsec_web-0.3.0/crates/parsec-js/scripts/gen-unicode.py +59 -0
  73. parsec_web-0.3.0/crates/parsec-js/src/ast.rs +899 -0
  74. parsec_web-0.3.0/crates/parsec-js/src/data/json.rs +260 -0
  75. parsec_web-0.3.0/crates/parsec-js/src/data/page.rs +427 -0
  76. parsec_web-0.3.0/crates/parsec-js/src/data.rs +381 -0
  77. parsec_web-0.3.0/crates/parsec-js/src/diagnostics.rs +262 -0
  78. parsec_web-0.3.0/crates/parsec-js/src/early.rs +116 -0
  79. parsec_web-0.3.0/crates/parsec-js/src/estree.rs +716 -0
  80. parsec_web-0.3.0/crates/parsec-js/src/lexer.rs +1371 -0
  81. parsec_web-0.3.0/crates/parsec-js/src/lib.rs +104 -0
  82. parsec_web-0.3.0/crates/parsec-js/src/module.rs +409 -0
  83. parsec_web-0.3.0/crates/parsec-js/src/parser/expr.rs +1249 -0
  84. parsec_web-0.3.0/crates/parsec-js/src/parser/function.rs +631 -0
  85. parsec_web-0.3.0/crates/parsec-js/src/parser/mod.rs +1017 -0
  86. parsec_web-0.3.0/crates/parsec-js/src/parser/module.rs +392 -0
  87. parsec_web-0.3.0/crates/parsec-js/src/parser/pattern.rs +311 -0
  88. parsec_web-0.3.0/crates/parsec-js/src/parser/stmt.rs +1003 -0
  89. parsec_web-0.3.0/crates/parsec-js/src/regexp/names.rs +554 -0
  90. parsec_web-0.3.0/crates/parsec-js/src/regexp.rs +1398 -0
  91. parsec_web-0.3.0/crates/parsec-js/src/reparse.rs +973 -0
  92. parsec_web-0.3.0/crates/parsec-js/src/scope.rs +1340 -0
  93. parsec_web-0.3.0/crates/parsec-js/src/text.rs +422 -0
  94. parsec_web-0.3.0/crates/parsec-js/src/token.rs +448 -0
  95. parsec_web-0.3.0/crates/parsec-js/src/unicode.rs +278 -0
  96. parsec_web-0.3.0/crates/parsec-xml/Cargo.toml +38 -0
  97. parsec_web-0.3.0/crates/parsec-xml/LICENSE +201 -0
  98. parsec_web-0.3.0/crates/parsec-xml/NOTICE +65 -0
  99. parsec_web-0.3.0/crates/parsec-xml/README.md +587 -0
  100. parsec_web-0.3.0/crates/parsec-xml/src/bytes.rs +173 -0
  101. parsec_web-0.3.0/crates/parsec-xml/src/chars.rs +170 -0
  102. parsec_web-0.3.0/crates/parsec-xml/src/dtd.rs +640 -0
  103. parsec_web-0.3.0/crates/parsec-xml/src/lib.rs +203 -0
  104. parsec_web-0.3.0/crates/parsec-xml/src/parse.rs +1569 -0
  105. parsec_web-0.3.0/crates/parsec-xml/src/serialize.rs +238 -0
  106. parsec_web-0.3.0/crates/parsec-xml/src/tree.rs +706 -0
  107. parsec_web-0.3.0/crates/parsec-xml/src/xpath_tree.rs +283 -0
  108. parsec_web-0.3.0/crates/parsec-xpath/Cargo.toml +27 -0
  109. parsec_web-0.3.0/crates/parsec-xpath/LICENSE +201 -0
  110. parsec_web-0.3.0/crates/parsec-xpath/NOTICE +70 -0
  111. parsec_web-0.3.0/crates/parsec-xpath/README.md +587 -0
  112. parsec_web-0.3.0/crates/parsec-xpath/src/eval.rs +1627 -0
  113. parsec_web-0.3.0/crates/parsec-xpath/src/html.rs +258 -0
  114. parsec_web-0.3.0/crates/parsec-xpath/src/index.rs +342 -0
  115. parsec_web-0.3.0/crates/parsec-xpath/src/lexer.rs +274 -0
  116. parsec_web-0.3.0/crates/parsec-xpath/src/lib.rs +310 -0
  117. parsec_web-0.3.0/crates/parsec-xpath/src/parser.rs +719 -0
  118. parsec_web-0.3.0/crates/parsec-xpath/src/tree.rs +118 -0
  119. parsec_web-0.3.0/pyproject.toml +38 -0
@@ -0,0 +1,14 @@
1
+ [workspace]
2
+ resolver = "3"
3
+ members = ["crates/parsec", "crates/parsec-web", "crates/parsec-capi", "crates/parsec-css", "crates/parsec-encoding", "crates/parsec-reduce", "crates/parsec-url", "crates/parsec-xpath", "crates/parsec-base", "crates/parsec-js", "crates/parsec-xml"]
4
+
5
+ [workspace.package]
6
+ version = "0.3.0"
7
+ edition = "2024"
8
+ license = "Apache-2.0"
9
+ repository = "https://github.com/parsec-html/parsec"
10
+ rust-version = "1.88"
11
+
12
+ [profile.release]
13
+ lto = "thin"
14
+ codegen-units = 1
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,70 @@
1
+ Parsec
2
+ Copyright 2026 James Conway
3
+
4
+ Parsec is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ Parsec's HTML parser includes the table of named character references
7
+ from the HTML Standard (https://html.spec.whatwg.org/), © WHATWG (Apple,
8
+ Google, Mozilla, Microsoft), licensed under the Creative Commons
9
+ Attribution 4.0 International License.
10
+
11
+ Parsec's HTML parser and its JavaScript lexer also include Unicode
12
+ property tables generated from the Unicode Character Database
13
+ (https://www.unicode.org/ucd/),
14
+ © 1991-2025 Unicode, Inc., licensed under the Unicode License v3
15
+ (https://www.unicode.org/license.txt).
16
+
17
+ Parsec's CSS module includes data generated from @webref/css
18
+ (https://github.com/w3c/webref), the CSS definitions scraped from the
19
+ specifications: every property's grammar, initial value, inheritance and
20
+ longhands, in crates/parsec-css/src/values/generated.rs, from
21
+ crates/parsec-css/data/webref/css.json, Copyright (c) 2020 World Wide Web
22
+ Consortium, under the MIT License; see the LICENSE file in that directory.
23
+
24
+ Parsec's CSS module also includes the user agent stylesheet from the
25
+ HTML Standard's rendering section
26
+ (https://html.spec.whatwg.org/multipage/rendering.html), in
27
+ crates/parsec-css/src/cascade/html.css, © WHATWG (Apple, Google, Mozilla,
28
+ Microsoft), licensed under the Creative Commons Attribution 4.0
29
+ International License.
30
+
31
+ Parsec's tests use test data that is not part of the library and is
32
+ licensed under its own terms:
33
+
34
+ - libxml2's XPath expression tests (https://gitlab.gnome.org/GNOME/libxml2),
35
+ in crates/parsec-xpath/tests/libxml2, Copyright (C) 1998-2012 Daniel
36
+ Veillard and the Libxml2 Contributors, under the MIT License; see the
37
+ Copyright file in that directory.
38
+ - html5lib-tests (https://github.com/html5lib/html5lib-tests), in
39
+ crates/parsec/tests/html5lib-tests, Copyright (c) 2006-2013 James
40
+ Graham, Geoffrey Sneddon, and other contributors, under the MIT
41
+ License; see the LICENSE file in that directory.
42
+ - The tree-construction tests from web-platform-tests
43
+ (https://github.com/web-platform-tests/wpt), in
44
+ crates/parsec/tests/tree-construction, Copyright web-platform-tests
45
+ contributors, under the 3-Clause BSD License; see the LICENSE.md file
46
+ in that directory.
47
+ - test262 (https://github.com/tc39/test262), in
48
+ crates/parsec-js/tests/test262, and the test262 files that seed the
49
+ lexer's fuzzing corpus, in crates/parsec-js/fuzz/corpus, Copyright
50
+ Ecma International and the test262 authors, under the BSD License;
51
+ see the LICENSE file in each directory.
52
+ - css-parsing-tests (https://github.com/CourtBouillon/css-parsing-tests),
53
+ in crates/parsec-css/tests/css-parsing-tests, written by Simon Sapin
54
+ and dedicated to the public domain under CC0 1.0; and its urange.json
55
+ from rust-cssparser (https://github.com/servo/rust-cssparser), in
56
+ crates/parsec-css/tests/urange, under the same dedication.
57
+ - css-tokenizer-tests (https://github.com/romainmenke/css-tokenizer-tests),
58
+ in crates/parsec-css/tests/css-tokenizer-tests, Copyright 2026 Romain
59
+ Menke, under the MIT License; see the LICENSE file in that directory.
60
+ - The CSS parsing tests from web-platform-tests
61
+ (https://github.com/web-platform-tests/wpt), as the cases extracted
62
+ into crates/parsec-css/tests/wpt-values, Copyright web-platform-tests
63
+ contributors, under the 3-Clause BSD License; see the LICENSE.md file
64
+ in that directory.
65
+ - web-platform-tests' media query, computed-value and cascade tests
66
+ (https://github.com/web-platform-tests/wpt), as the cases extracted
67
+ into crates/parsec-css/tests/wpt-media, wpt-computed and wpt-cascade,
68
+ with the test files those cases come from, Copyright
69
+ web-platform-tests contributors, under the 3-Clause BSD License; see
70
+ the LICENSE.md file in each directory.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.4
2
+ Name: parsec-web
3
+ Version: 0.3.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Python :: 3.10
7
+ Classifier: Programming Language :: Python :: 3.11
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Classifier: Programming Language :: Python :: 3.14
11
+ Classifier: Programming Language :: Python :: 3.15
12
+ Classifier: Programming Language :: Python :: Implementation :: CPython
13
+ Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
14
+ Classifier: Programming Language :: Rust
15
+ Classifier: Topic :: Text Processing :: Markup :: HTML
16
+ License-File: LICENSE
17
+ License-File: NOTICE
18
+ Summary: A fast, spec-following HTML parser with CSS selectors and an editable tree, with a selectolax-style API.
19
+ Keywords: html,parser,html5,css-selectors,selectolax
20
+ License-Expression: Apache-2.0
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
23
+ Project-URL: Documentation, https://github.com/parsec-html/parsec/wiki/Python
24
+ Project-URL: Homepage, https://github.com/parsec-html/parsec
25
+ Project-URL: Issues, https://github.com/parsec-html/parsec/issues
26
+
27
+ # parsec-web for Python
28
+
29
+ Parsec is an HTML parser in Rust that reads pages the way a browser does,
30
+ finds what you want with CSS selectors, and lets you change the tree and
31
+ write it back out. This is its Python package, and if you've used
32
+ selectolax you already know the API:
33
+
34
+ ```python
35
+ from parsec_html import HTMLParser
36
+
37
+ page = HTMLParser("<ul><li class=hit>one<li>two</ul>")
38
+ assert page.css_first("li.hit").text() == "one"
39
+ for li in page.css("li"):
40
+ print(li.tag, li.attributes, li.html)
41
+ ```
42
+
43
+ What you get over selectolax:
44
+
45
+ - **Threads.** One parsed page can be read from as many threads as you
46
+ like, and edited from any of them. On free-threaded Python (3.14t
47
+ and later) the module runs with the GIL off, and on any Python, parsing and
48
+ `css()` let go of it while they work.
49
+ - **Selectors selectolax 1.0.2 won't run**: `:lang()`, `:dir()`,
50
+ `:valid`, `:in-range`, `:scope` and more, which it rejects as
51
+ unparseable, and `:target` and `:local-link` once you pass the page's
52
+ `url`.
53
+ - **Limits** for pages you don't trust: `budget=` (seconds) and
54
+ `max_depth=` when you parse, and `max_steps=` and `budget=` on `css()`
55
+ and the other selector calls, so a hostile `:has()` can't hold a worker
56
+ for minutes. A limit that runs out raises `TimeoutError`; you never get
57
+ half the matches.
58
+
59
+ ```python
60
+ page.css("div:has(span div)", max_steps=10_000_000, budget=0.5)
61
+ ```
62
+ - **Nodes that outlive edits.** A removed node can still be read, and put
63
+ back.
64
+ - **XPath 1.0**, which selectolax doesn't have. `xpath()` gives back what
65
+ lxml's does, so code written for lxml or parsel reads the same:
66
+
67
+ ```python
68
+ page.xpath("//li/text()") # ['one', 'two']
69
+ page.xpath("count(//li)") # 2.0
70
+ page.xpath("//a[@rel=$r]/@href", r="next")
71
+ ```
72
+
73
+ Elements and comments come back as nodes, text and attribute values as
74
+ `str`, and a number, string or boolean as `float`, `str` or `bool`.
75
+ One place they part: a number turned into a string follows XPath 1.0
76
+ here, shortest digits and never an exponent. So `string(0.1 + 0.2)` is
77
+ `'0.30000000000000004'`, where lxml rounds to 15 digits and says `'0.3'`,
78
+ and 10<sup>16</sup> comes out as `'10000000000000000'`, not `'1e+16'`.
79
+ - **Where everything was written.** Parse with `positions=True` and every
80
+ node knows its place in your input: `node.source_range` and
81
+ `node.end_tag_range` are `(start, end)` indexes into what you passed
82
+ (code points into a `str`, bytes into `bytes`), so `src[start:end]` is
83
+ the tag as you wrote it; `node.position` is
84
+ its `(line, column)`, and `node.attribute_range("href")` finds one
85
+ attribute.
86
+ - **Parse errors.** With `errors=True`, `page.errors` lists each one with
87
+ the HTML Standard's name for it and where it is:
88
+ `2:1: unexpected-end-tag`.
89
+ - **Bytes in any encoding.** Hand `HTMLParser` the `bytes` you
90
+ downloaded and it decodes them as a browser would: a byte order mark
91
+ first, then the HTTP `charset`, which you pass as `transport_encoding`,
92
+ then a `<meta>`, then UTF-8 if the bytes are valid UTF-8, then
93
+ `default_encoding` (windows-1252 unless you say otherwise;
94
+ `encoding_for_locale("ja")` gives the one a Japanese browser uses). `page.encoding` says which it was, and
95
+ `page.encoding_confidence` whether it's `"certain"` or `"tentative"`.
96
+ Positions stay byte offsets into your bytes, whatever the encoding.
97
+
98
+ ```python
99
+ with urllib.request.urlopen(url) as r:
100
+ page = HTMLParser(r.read(), transport_encoding=r.headers.get_content_charset())
101
+ page.encoding # 'Shift_JIS'
102
+ ```
103
+
104
+ A `charset` that names no encoding is passed over, as browsers pass
105
+ it over.
106
+
107
+ `StreamParser` does the same as the bytes arrive, and you get the same
108
+ page however they're cut:
109
+
110
+ ```python
111
+ with urllib.request.urlopen(url) as r:
112
+ s = StreamParser(transport_encoding=r.headers.get_content_charset())
113
+ while chunk := r.read(65536):
114
+ s.feed(chunk)
115
+ page = s.close() # an HTMLParser
116
+ ```
117
+
118
+ The names are those of lxml's feed parser and the standard library's
119
+ `html.parser`; the keywords are html5lib's.
120
+
121
+ **A small change.** `bytes` used to be read as UTF-8 whatever they
122
+ were. UTF-8 still comes out as UTF-8, declared or not. Bytes that
123
+ aren't valid UTF-8 and don't say what they are used to get U+FFFD in
124
+ place of each bad byte; now they decode as windows-1252, as in a
125
+ browser. Pass `transport_encoding` if you know better.
126
+ - **JavaScript.** `parsec_html.js.parse()` gives a script's ESTree, the
127
+ tree acorn and ESLint use, as dicts and lists; `module=True` parses a
128
+ module. `start` and `end` are indexes into your `str`. A syntax error
129
+ raises `JSSyntaxError`, a `ValueError` with `code`, `line`, `column`,
130
+ `start`, `end` and the `frame` a compiler would print:
131
+
132
+ ```python
133
+ from parsec_html import js
134
+
135
+ tree = js.parse("export const a = [1, 2];", module=True)
136
+ tree["body"][0]["declaration"]["declarations"][0]["init"]["type"] # 'ArrayExpression'
137
+ try:
138
+ js.parse("let x = ;")
139
+ except js.JSSyntaxError as e:
140
+ print(e.frame)
141
+ ```
142
+
143
+ `max_depth=` (at most and by default 256) and `max_steps=` bound a
144
+ script you don't trust: too deep raises `JSSyntaxError` with the code
145
+ `too-deep`, and past the steps, `TimeoutError`.
146
+ - **The state pages keep in scripts**, read without running anything:
147
+ `window.__NUXT__ = …`, a top-level `var ytInitialData = …`,
148
+ `JSON.parse("…")`, Nuxt 2's function form and Next.js's
149
+ `self.__next_f` pushes. `page.page_state()` reads every inline script
150
+ on a page; `js.page_state(source)` reads one.
151
+
152
+ ```python
153
+ page = HTMLParser(html)
154
+ for found in page.page_state():
155
+ print(found["name"], found.get("value", found.get("error")))
156
+ ```
157
+
158
+ Each is `{"name", "value"}`, or `{"name", "error": {"code", "source"}}`
159
+ when the value would need code to run, like `window.x = f()`.
160
+
161
+ ## Installing
162
+
163
+ ```sh
164
+ pip install parsec-web
165
+ ```
166
+
167
+ The package was `parsec-html` up to 0.2. The module is still
168
+ `parsec_html`, so moving up changes nothing in your code.
169
+
170
+ There are wheels for CPython 3.10 and newer, free-threaded too, on Linux
171
+ (glibc and musl), macOS and Windows, x86-64 and ARM. Anywhere else, pip
172
+ builds the sdist, which needs Rust 1.88 or newer. The newest code on
173
+ `main` installs the same way from git:
174
+
175
+ ```sh
176
+ pip install "git+https://github.com/parsec-html/parsec#subdirectory=bindings/python"
177
+ ```
178
+
179
+ ## Moving from selectolax
180
+
181
+ Change the import, and most code runs as it was:
182
+
183
+ ```python
184
+ # from selectolax.lexbor import LexborHTMLParser as HTMLParser
185
+ from parsec_html import HTMLParser
186
+ ```
187
+
188
+ `HTMLParser(html, is_fragment=False, fragment_tag="div",
189
+ fragment_namespace="html", scripting=False)` takes what
190
+ `LexborHTMLParser` does (plus `budget`, `max_depth`, `url`, `positions`,
191
+ `errors`, `transport_encoding` and `default_encoding`), and the parser and its nodes have selectolax's
192
+ names: `root`, `head`, `body`, `html`, `css`, `css_first` (with `default`
193
+ and `strict`), `css_matches`, `any_css_matches`, `tags`, `text(deep,
194
+ separator, strip, skip_empty)`, `merge_text_nodes`, `strip_tags`,
195
+ `unwrap_tags`, `create_node`; on a node also `tag`, `id`, `attributes`,
196
+ `attrs`, `inner_html` (which you can set), `text_content`,
197
+ `comment_content`, `parent`, `next`, `prev`, `first_child`, `last_child`,
198
+ `iter`, `traverse`, `decompose`, `remove`, `unwrap`, `replace_with`,
199
+ `insert_before`, `insert_after`, `insert_child` (all four taking a string
200
+ as text, or a node to copy, or to move with `move=True`), and the
201
+ `is_*_node` checks.
202
+
203
+ Where it behaves differently:
204
+
205
+ | | selectolax 1.0.2 | parsec_html |
206
+ |---|---|---|
207
+ | `<a href>`'s `attributes` | `{'href': None}` | `{'href': ''}`: Parsec doesn't yet record whether a value was written |
208
+ | A selector that doesn't parse | `SelectolaxError` | `SelectorError`, a `ValueError` |
209
+ | A node after `decompose()` | freed | reads as empty (no parent, children, attributes or text, `html` is `""`, no selector matches) but keeps its `tag`; `xpath()` and putting it back raise `ValueError` |
210
+ | `remove()` | the same as `decompose()` | takes the node out but keeps it readable, to put back with `move=True` |
211
+ | `root.decompose()` | `SelectolaxError` | decomposes `<html>`; only the document node itself raises `ValueError` |
212
+ | `attrs.items()`, `keys()`, `values()` | iterators | lists |
213
+ | `bytes` in | UTF-8, or sniffed with `encoding=True` | sniffed as a browser sniffs them: byte order mark, `transport_encoding`, `<meta>`, then `default_encoding` |
214
+ | Class names | `LexborHTMLParser`, `LexborNode` | `HTMLParser`, `Node` |
215
+
216
+ Not there yet: `clone()`, `raw_html`, `raw_value`, `html_pretty`,
217
+ `inner_html_pretty`, the parser's `inner_html`, `options` and `selector`,
218
+ `select()` and its filters, `scripts_contain`, `script_srcs_contain`,
219
+ `template_fragments`, `text_lexbor`, `mem_id`, `tag_id` and the
220
+ `:lexbor-contains()` pseudo-class.
221
+
222
+ ## XML
223
+
224
+ `parsec_html.xml.parse()` reads XML 1.0 with namespaces, from a `str`
225
+ or from `bytes` in the encoding they declare. It doesn't validate, and
226
+ it never fetches anything: an external DTD is left unread, and
227
+ `doc.warnings` says so.
228
+
229
+ ```python
230
+ from parsec_html import xml
231
+
232
+ doc = xml.parse(open("feed.atom", "rb").read())
233
+ feed = doc.root # the document element
234
+ feed.namespace # 'http://www.w3.org/2005/Atom'
235
+ for entry in feed.children:
236
+ if entry.kind == "element":
237
+ print(entry.local_name, entry.attribute("href", "http://www.w3.org/1999/xlink"))
238
+ doc.xml # the document, written back out
239
+ ```
240
+
241
+ A node has the HTML parser's names where they mean the same thing:
242
+ `tag` (the name as written, `atom:link`), `parent`, `next`, `prev`,
243
+ `first_child`, `last_child`, `attributes`, `text()`, `source_range` and
244
+ `position`. What namespaces add is `local_name`, `prefix`, `namespace`,
245
+ `attribute(local_name, namespace)` and `attribute_list`, whose
246
+ `XMLAttribute`s carry the same four parts and the value. `kind` says
247
+ what the node is, `value` is a text, CDATA or comment node's text, and
248
+ `xml` writes a node back out, with the namespace declarations an
249
+ element alone needs.
250
+
251
+ XML that isn't well-formed raises `XMLSyntaxError`, a `ValueError`
252
+ with `code`, `message`, `line` and `column`. So does XML past its
253
+ limits, which you can tighten: `max_depth=` (2,048 unless you give
254
+ one), `max_entity_depth=` (16), and entity expansion of
255
+ `entity_allowance=` bytes (1 MiB) plus `entity_ratio=` (8) per byte of
256
+ input, which stops a billion laughs at once. `namespaces=False` reads
257
+ names as they are, colons and all. A document can't be changed, and
258
+ any number of threads can read one at once.
259
+
260
+ ## Speed
261
+
262
+ `bench.py` times both on the 13 real pages `bench/` uses (24 MB in all):
263
+
264
+ | | parsec_html | selectolax | |
265
+ |---|---:|---:|---:|
266
+ | Parse all 13 pages | 66 ms | 106 ms | 1.6× |
267
+ | The 32 selectors over all 13 | 283 ms | 781 ms | 2.8× |
268
+ | Every link's `href` and text | 43 ms | 50 ms | 1.2× |
269
+
270
+ Parsec parses each of the 13 pages faster, by 1.5 to 2.8 times, and runs
271
+ each of the 32 selectors faster, by 1.04 to 29 times
272
+ (`p:nth-child(2n+1)`). The narrowest margins are the selectors that
273
+ match most of a page, such as `*` and `[class]`, where the time goes on
274
+ making a Python object per match. Medians of 20 runs on an Apple M2 Max,
275
+ CPython 3.14, at a load of 3; a second run gave the same to within 6%.
276
+
277
+ ## Working on it
278
+
279
+ ```sh
280
+ cd bindings/python
281
+ pip install maturin pytest
282
+ maturin develop --release
283
+ pytest tests
284
+ python bench.py # after bench/fetch-pages.sh and pip install selectolax
285
+ ```
286
+
287
+ The [Python page](https://github.com/parsec-html/parsec/wiki/Python) on
288
+ the wiki has the whole API.
289
+