selectolax 0.3.30__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of selectolax might be problematic. Click here for more details.

selectolax/parser.pyi ADDED
@@ -0,0 +1,323 @@
1
+ from typing import Iterator, TypeVar, Literal, overload
2
+
3
+ DefaultT = TypeVar("DefaultT")
4
+
5
+ class _Attributes:
6
+ @staticmethod
7
+ def create(node: Node, decode_errors: str) -> _Attributes: ...
8
+ def keys(self) -> Iterator[str]: ...
9
+ def items(self) -> Iterator[tuple[str, str | None]]: ...
10
+ def values(self) -> Iterator[str | None]: ...
11
+ def __iter__(self) -> Iterator[str]: ...
12
+ def __len__(self) -> int: ...
13
+ def __getitem__(self, key: str) -> str | None: ...
14
+ def __setitem__(self, key: str, value: str) -> None: ...
15
+ def __delitem__(self, key: str) -> None: ...
16
+ def __contains__(self, key: str) -> bool: ...
17
+ def __repr__(self) -> str: ...
18
+ @overload
19
+ def get(self, key: str, default: DefaultT) -> DefaultT | str | None: ...
20
+ @overload
21
+ def get(self, key: str, default: None = ...) -> str | None: ...
22
+ @overload
23
+ def sget(self, key: str, default: str | DefaultT) -> str | DefaultT: ...
24
+ @overload
25
+ def sget(self, key: str, default: str = "") -> str: ...
26
+
27
+ class Selector:
28
+ """An advanced CSS selector that supports additional operations.
29
+
30
+ Think of it as a toolkit that mimics some of the features of XPath.
31
+
32
+ Please note, this is an experimental feature that can change in the future."""
33
+
34
+ def __init__(self, node: Node, query: str): ...
35
+ def css(self, query: str) -> Node:
36
+ """Evaluate CSS selector against current scope."""
37
+ ...
38
+ @property
39
+ def matches(self) -> list[Node]:
40
+ """Returns all possible selector matches"""
41
+ ...
42
+ @property
43
+ def any_matches(self) -> bool:
44
+ """Returns True if there are any matches"""
45
+ ...
46
+ def text_contains(
47
+ self, text: str, deep: bool = True, separator: str = "", strip: bool = False
48
+ ) -> Selector:
49
+ """Filter all current matches given text."""
50
+ ...
51
+ def any_text_contains(
52
+ self, text: str, deep: bool = True, separator: str = "", strip: bool = False
53
+ ) -> bool:
54
+ """Returns True if any node in the current search scope contains specified text"""
55
+ ...
56
+ def attribute_longer_than(
57
+ self, text: str, length: int, start: str | None = None
58
+ ) -> Selector:
59
+ """Filter all current matches by attribute length.
60
+
61
+ Similar to string-length in XPath."""
62
+ ...
63
+ def any_attribute_longer_than(
64
+ self, text: str, length: int, start: str | None = None
65
+ ) -> bool:
66
+ """Returns True any href attribute longer than a specified length.
67
+
68
+ Similar to string-length in XPath."""
69
+ ...
70
+
71
+ class Node:
72
+ parser: HTMLParser
73
+ @property
74
+ def attributes(self) -> dict[str, str | None]:
75
+ """Get all attributes that belong to the current node.
76
+
77
+ The value of empty attributes is None."""
78
+ ...
79
+ @property
80
+ def attrs(self) -> _Attributes:
81
+ """A dict-like object that is similar to the attributes property, but operates directly on the Node data."""
82
+ ...
83
+ @property
84
+ def id(self) -> str | None:
85
+ """Get the id attribute of the node.
86
+
87
+ Returns None if id does not set."""
88
+ ...
89
+
90
+ def mem_id(self) -> int:
91
+ """Get the mem_id of the node.
92
+
93
+ Returns 0 if mem_id does not set."""
94
+ ...
95
+
96
+ def __hash__(self) -> int:
97
+ """ Get the hash of this node
98
+ :return: int
99
+ """
100
+ ...
101
+ def text(self, deep: bool = True, separator: str = "", strip: bool = False) -> str:
102
+ """Returns the text of the node including text of all its child nodes."""
103
+ ...
104
+ def iter(self, include_text: bool = False) -> Iterator[Node]:
105
+ """Iterate over nodes on the current level."""
106
+ ...
107
+ def traverse(self, include_text: bool = False) -> Iterator[Node]:
108
+ """Iterate over all child and next nodes starting from the current level."""
109
+ ...
110
+ @property
111
+ def tag(self) -> str:
112
+ """Return the name of the current tag (e.g. div, p, img)."""
113
+ ...
114
+ @property
115
+ def child(self) -> Node | None:
116
+ """Return the child node."""
117
+ ...
118
+ @property
119
+ def parent(self) -> Node | None:
120
+ """Return the parent node."""
121
+ ...
122
+ @property
123
+ def next(self) -> Node | None:
124
+ """Return next node."""
125
+ ...
126
+ @property
127
+ def prev(self) -> Node | None:
128
+ """Return previous node."""
129
+ ...
130
+ @property
131
+ def last_child(self) -> Node | None:
132
+ """Return last child node."""
133
+ ...
134
+ @property
135
+ def html(self) -> str | None:
136
+ """Return HTML representation of the current node including all its child nodes."""
137
+ ...
138
+ def css(self, query: str) -> list[Node]:
139
+ """Evaluate CSS selector against current node and its child nodes."""
140
+ ...
141
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
142
+ """Returns True if any of CSS selectors matches a node"""
143
+ ...
144
+ def css_matches(self, selector: str) -> bool:
145
+ """Returns True if CSS selector matches a node."""
146
+ ...
147
+ @overload
148
+ def css_first(
149
+ self, query: str, default: DefaultT, strict: bool = False
150
+ ) -> Node | DefaultT:
151
+ ...
152
+ @overload
153
+ def css_first(
154
+ self, query: str, default: None = None, strict: bool = False
155
+ ) -> Node | None | DefaultT:
156
+ ...
157
+ def decompose(self, recursive: bool = True) -> None:
158
+ """Remove a Node from the tree."""
159
+ ...
160
+ def remove(self, recursive: bool = True) -> None:
161
+ """An alias for the decompose method."""
162
+ ...
163
+ def unwrap(self) -> None:
164
+ """Replace node with whatever is inside this node."""
165
+ ...
166
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None:
167
+ """Remove specified tags from the HTML tree."""
168
+ ...
169
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
170
+ """Unwraps specified tags from the HTML tree.
171
+
172
+ Works the same as the unwrap method, but applied to a list of tags."""
173
+ ...
174
+ def replace_with(self, value: str | bytes | None) -> None:
175
+ """Replace current Node with specified value."""
176
+ ...
177
+ def insert_before(self, value: str | bytes | None) -> None:
178
+ """Insert a node before the current Node."""
179
+ ...
180
+ def insert_after(self, value: str | bytes | None) -> None:
181
+ """Insert a node after the current Node."""
182
+ ...
183
+ def insert_child(self, value: str | bytes | None) -> None:
184
+ """Insert a node inside (at the end of) the current Node.."""
185
+ ...
186
+ @property
187
+ def raw_value(self) -> bytes:
188
+ """Return the raw (unparsed, original) value of a node.
189
+
190
+ Currently, works on text nodes only."""
191
+ ...
192
+ def select(self, query: str | None = None) -> Selector:
193
+ """Select nodes given a CSS selector.
194
+
195
+ Works similarly to the css method, but supports chained filtering and extra features.
196
+ """
197
+ ...
198
+ def scripts_contain(self, query: str) -> bool:
199
+ """Returns True if any of the script tags contain specified text.
200
+
201
+ Caches script tags on the first call to improve performance."""
202
+ ...
203
+ def script_srcs_contain(self, queries: tuple[str]) -> bool:
204
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
205
+
206
+ Caches values on the first call to improve performance."""
207
+ ...
208
+ @property
209
+ def text_content(self) -> str | None:
210
+ """Returns the text of the node if it is a text node.
211
+
212
+ Returns None for other nodes. Unlike the text method, does not include child nodes.
213
+ """
214
+ ...
215
+ def merge_text_nodes(self):
216
+ """Iterates over all text nodes and merges all text nodes that are close to each other.
217
+
218
+ This is useful for text extraction."""
219
+ ...
220
+
221
+ class HTMLParser:
222
+ def __init__(
223
+ self,
224
+ html: bytes | str,
225
+ detect_encoding: bool = True,
226
+ use_meta_tags: bool = True,
227
+ decode_errors: Literal["strict", "ignore", "replace"] = "ignore",
228
+ ): ...
229
+ def css(self, query: str) -> list[Node]:
230
+ """A CSS selector.
231
+
232
+ Matches pattern query against HTML tree."""
233
+ ...
234
+ @overload
235
+ def css_first(
236
+ self, query: str, default: DefaultT, strict: bool = False
237
+ ) -> Node | DefaultT:
238
+ ...
239
+
240
+ @overload
241
+ def css_first(
242
+ self, query: str, default: None = None, strict: bool = False
243
+ ) -> Node | None | DefaultT:
244
+ ...
245
+ @property
246
+ def input_encoding(self) -> str:
247
+ """Return encoding of the HTML document.
248
+
249
+ Returns unknown in case the encoding is not determined."""
250
+ ...
251
+ @property
252
+ def root(self) -> Node | None:
253
+ """Returns root node."""
254
+ ...
255
+ @property
256
+ def head(self) -> Node | None:
257
+ """Returns head node."""
258
+ ...
259
+ @property
260
+ def body(self) -> Node | None:
261
+ """Returns document body."""
262
+ ...
263
+ def tags(self, name: str) -> list[Node]:
264
+ """Returns a list of tags that match specified name."""
265
+ ...
266
+ def text(self, deep: bool = True, separator: str = "", strip: bool = False) -> str:
267
+ """Returns the text of the node including text of all its child nodes."""
268
+ ...
269
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None: ...
270
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
271
+ """Unwraps specified tags from the HTML tree.
272
+
273
+ Works the same as th unwrap method, but applied to a list of tags."""
274
+ ...
275
+ @property
276
+ def html(self) -> str | None:
277
+ """Return HTML representation of the page."""
278
+ ...
279
+ def select(self, query: str | None = None) -> Selector | None:
280
+ """Select nodes given a CSS selector.
281
+
282
+ Works similarly to the css method, but supports chained filtering and extra features.
283
+ """
284
+ ...
285
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
286
+ """Returns True if any of the specified CSS selectors matches a node."""
287
+ ...
288
+ def scripts_contain(self, query: str) -> bool:
289
+ """Returns True if any of the script tags contain specified text.
290
+
291
+ Caches script tags on the first call to improve performance."""
292
+ ...
293
+ def scripts_srcs_contain(self, queries: tuple[str]) -> bool:
294
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
295
+
296
+ Caches values on the first call to improve performance."""
297
+ ...
298
+ def css_matches(self, selector: str) -> bool: ...
299
+ def clone(self) -> HTMLParser:
300
+ """Clone the current tree."""
301
+ ...
302
+ def merge_text_nodes(self):
303
+ """Iterates over all text nodes and merges all text nodes that are close to each other.
304
+
305
+ This is useful for text extraction."""
306
+ ...
307
+
308
+ def create_tag(tag: str) -> Node:
309
+ """
310
+ Given an HTML tag name, e.g. `"div"`, create a single empty node for that tag,
311
+ e.g. `"<div></div>"`.
312
+ """
313
+ ...
314
+
315
+ def parse_fragment(html: str) -> list[Node]:
316
+ """
317
+ Given HTML, parse it into a list of Nodes, such that the nodes
318
+ correspond to the given HTML.
319
+
320
+ For contrast, HTMLParser adds `<html>`, `<head>`, and `<body>` tags
321
+ if they are missing. This function does not add these tags.
322
+ """
323
+ ...