massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stubs / beautifulsoup4 / bs4 / element.pyi
1 from _typeshed import Self
2 from collections.abc import Iterator
3 from typing import Any, Callable, Generic, Iterable, List, Mapping, Pattern, Tuple, Type, TypeVar, Union, overload
4
5 from . import BeautifulSoup
6 from .builder import TreeBuilder
7 from .formatter import Formatter, _EntitySubstitution
8
9 DEFAULT_OUTPUT_ENCODING: str
10 PY3K: bool
11 nonwhitespace_re: Pattern[str]
12 whitespace_re: Pattern[str]
13 PYTHON_SPECIFIC_ENCODINGS: set[str]
14
15 class NamespacedAttribute(str):
16     def __new__(cls: Type[Self], prefix: str, name: str | None = ..., namespace: str | None = ...) -> Self: ...
17
18 class AttributeValueWithCharsetSubstitution(str): ...
19
20 class CharsetMetaAttributeValue(AttributeValueWithCharsetSubstitution):
21     def __new__(cls, original_value): ...
22     def encode(self, encoding: str) -> str: ...  # type: ignore  # incompatible with str
23
24 class ContentMetaAttributeValue(AttributeValueWithCharsetSubstitution):
25     CHARSET_RE: Pattern[str]
26     def __new__(cls, original_value): ...
27     def encode(self, encoding: str) -> str: ...  # type: ignore  # incompatible with str
28
29 _PageElementT = TypeVar("_PageElementT", bound=PageElement)
30 # The wrapping Union[] can be removed once mypy fully supports | in type aliases.
31 _SimpleStrainable = Union[str, bool, None, bytes, Pattern[str], Callable[[str], bool], Callable[[Tag], bool]]
32 _Strainable = Union[_SimpleStrainable, Iterable[_SimpleStrainable]]
33 _SimpleNormalizedStrainable = Union[str, bool, None, Pattern[str], Callable[[str], bool], Callable[[Tag], bool]]
34 _NormalizedStrainable = Union[_SimpleNormalizedStrainable, Iterable[_SimpleNormalizedStrainable]]
35
36 class PageElement:
37     parent: Tag | None
38     previous_element: PageElement | None
39     next_element: PageElement | None
40     next_sibling: PageElement | None
41     previous_sibling: PageElement | None
42     def setup(
43         self,
44         parent: Tag | None = ...,
45         previous_element: PageElement | None = ...,
46         next_element: PageElement | None = ...,
47         previous_sibling: PageElement | None = ...,
48         next_sibling: PageElement | None = ...,
49     ) -> None: ...
50     def format_string(self, s: str, formatter: Formatter | str | None) -> str: ...
51     def formatter_for_name(self, formatter: Formatter | str | _EntitySubstitution): ...
52     nextSibling: PageElement | None
53     previousSibling: PageElement | None
54     @property
55     def stripped_strings(self) -> Iterator[str]: ...
56     def get_text(self, separator: str = ..., strip: bool = ..., types: Tuple[Type[NavigableString], ...] = ...) -> str: ...
57     getText = get_text
58     @property
59     def text(self) -> str: ...
60     def replace_with(self: Self, *args: PageElement | str) -> Self: ...
61     replaceWith = replace_with
62     def unwrap(self: Self) -> Self: ...
63     replace_with_children = unwrap
64     replaceWithChildren = unwrap
65     def wrap(self, wrap_inside: _PageElementT) -> _PageElementT: ...
66     def extract(self: Self, _self_index: int | None = ...) -> Self: ...
67     def insert(self, position: int, new_child: PageElement | str) -> None: ...
68     def append(self, tag: PageElement | str) -> None: ...
69     def extend(self, tags: Iterable[PageElement | str]) -> None: ...
70     def insert_before(self, *args: PageElement | str) -> None: ...
71     def insert_after(self, *args: PageElement | str) -> None: ...
72     def find_next(
73         self,
74         name: _Strainable | SoupStrainer | None = ...,
75         attrs: dict[str, _Strainable] | _Strainable = ...,
76         text: _Strainable | None = ...,
77         **kwargs: _Strainable,
78     ) -> Tag | NavigableString | None: ...
79     findNext = find_next
80     def find_all_next(
81         self,
82         name: _Strainable | SoupStrainer | None = ...,
83         attrs: dict[str, _Strainable] | _Strainable = ...,
84         text: _Strainable | None = ...,
85         limit: int | None = ...,
86         **kwargs: _Strainable,
87     ) -> ResultSet[PageElement]: ...
88     findAllNext = find_all_next
89     def find_next_sibling(
90         self,
91         name: _Strainable | SoupStrainer | None = ...,
92         attrs: dict[str, _Strainable] | _Strainable = ...,
93         text: _Strainable | None = ...,
94         **kwargs: _Strainable,
95     ) -> Tag | NavigableString | None: ...
96     findNextSibling = find_next_sibling
97     def find_next_siblings(
98         self,
99         name: _Strainable | SoupStrainer | None = ...,
100         attrs: dict[str, _Strainable] | _Strainable = ...,
101         text: _Strainable | None = ...,
102         limit: int | None = ...,
103         **kwargs: _Strainable,
104     ) -> ResultSet[PageElement]: ...
105     findNextSiblings = find_next_siblings
106     fetchNextSiblings = find_next_siblings
107     def find_previous(
108         self,
109         name: _Strainable | SoupStrainer | None = ...,
110         attrs: dict[str, _Strainable] | _Strainable = ...,
111         text: _Strainable | None = ...,
112         **kwargs: _Strainable,
113     ) -> Tag | NavigableString | None: ...
114     findPrevious = find_previous
115     def find_all_previous(
116         self,
117         name: _Strainable | SoupStrainer | None = ...,
118         attrs: dict[str, _Strainable] | _Strainable = ...,
119         text: _Strainable | None = ...,
120         limit: int | None = ...,
121         **kwargs: _Strainable,
122     ) -> ResultSet[PageElement]: ...
123     findAllPrevious = find_all_previous
124     fetchPrevious = find_all_previous
125     def find_previous_sibling(
126         self,
127         name: _Strainable | SoupStrainer | None = ...,
128         attrs: dict[str, _Strainable] | _Strainable = ...,
129         text: _Strainable | None = ...,
130         **kwargs: _Strainable,
131     ) -> Tag | NavigableString | None: ...
132     findPreviousSibling = find_previous_sibling
133     def find_previous_siblings(
134         self,
135         name: _Strainable | SoupStrainer | None = ...,
136         attrs: dict[str, _Strainable] | _Strainable = ...,
137         text: _Strainable | None = ...,
138         limit: int | None = ...,
139         **kwargs: _Strainable,
140     ) -> ResultSet[PageElement]: ...
141     findPreviousSiblings = find_previous_siblings
142     fetchPreviousSiblings = find_previous_siblings
143     def find_parent(
144         self,
145         name: _Strainable | SoupStrainer | None = ...,
146         attrs: dict[str, _Strainable] | _Strainable = ...,
147         **kwargs: _Strainable,
148     ) -> Tag | None: ...
149     findParent = find_parent
150     def find_parents(
151         self,
152         name: _Strainable | SoupStrainer | None = ...,
153         attrs: dict[str, _Strainable] | _Strainable = ...,
154         limit: int | None = ...,
155         **kwargs: _Strainable,
156     ) -> ResultSet[Tag]: ...
157     findParents = find_parents
158     fetchParents = find_parents
159     @property
160     def next(self) -> Tag | NavigableString | None: ...
161     @property
162     def previous(self) -> Tag | NavigableString | None: ...
163     @property
164     def next_elements(self) -> Iterable[PageElement]: ...
165     @property
166     def next_siblings(self) -> Iterable[PageElement]: ...
167     @property
168     def previous_elements(self) -> Iterable[PageElement]: ...
169     @property
170     def previous_siblings(self) -> Iterable[PageElement]: ...
171     @property
172     def parents(self) -> Iterable[Tag]: ...
173     @property
174     def decomposed(self) -> bool: ...
175     def nextGenerator(self) -> Iterable[PageElement]: ...
176     def nextSiblingGenerator(self) -> Iterable[PageElement]: ...
177     def previousGenerator(self) -> Iterable[PageElement]: ...
178     def previousSiblingGenerator(self) -> Iterable[PageElement]: ...
179     def parentGenerator(self) -> Iterable[Tag]: ...
180
181 class NavigableString(str, PageElement):
182     PREFIX: str
183     SUFFIX: str
184     known_xml: bool | None
185     def __new__(cls: Type[Self], value: str | bytes) -> Self: ...
186     def __copy__(self: Self) -> Self: ...
187     def __getnewargs__(self) -> tuple[str]: ...
188     def output_ready(self, formatter: Formatter | str | None = ...) -> str: ...
189     @property
190     def name(self) -> None: ...
191     @property
192     def strings(self) -> Iterable[str]: ...
193
194 class PreformattedString(NavigableString):
195     PREFIX: str
196     SUFFIX: str
197     def output_ready(self, formatter: Formatter | str | None = ...) -> str: ...
198
199 class CData(PreformattedString):
200     PREFIX: str
201     SUFFIX: str
202
203 class ProcessingInstruction(PreformattedString):
204     PREFIX: str
205     SUFFIX: str
206
207 class XMLProcessingInstruction(ProcessingInstruction):
208     PREFIX: str
209     SUFFIX: str
210
211 class Comment(PreformattedString):
212     PREFIX: str
213     SUFFIX: str
214
215 class Declaration(PreformattedString):
216     PREFIX: str
217     SUFFIX: str
218
219 class Doctype(PreformattedString):
220     @classmethod
221     def for_name_and_ids(cls, name: str | None, pub_id: str, system_id: str) -> Doctype: ...
222     PREFIX: str
223     SUFFIX: str
224
225 class Stylesheet(NavigableString): ...
226 class Script(NavigableString): ...
227 class TemplateString(NavigableString): ...
228
229 class Tag(PageElement):
230     parser_class: Type[BeautifulSoup] | None
231     name: str
232     namespace: str | None
233     prefix: str | None
234     sourceline: int | None
235     sourcepos: int | None
236     known_xml: bool | None
237     attrs: Mapping[str, str]
238     contents: list[PageElement]
239     hidden: bool
240     can_be_empty_element: bool | None
241     cdata_list_attributes: list[str] | None
242     preserve_whitespace_tags: list[str] | None
243     def __init__(
244         self,
245         parser: BeautifulSoup | None = ...,
246         builder: TreeBuilder | None = ...,
247         name: str | None = ...,
248         namespace: str | None = ...,
249         prefix: str | None = ...,
250         attrs: Mapping[str, str] | None = ...,
251         parent: Tag | None = ...,
252         previous: PageElement | None = ...,
253         is_xml: bool | None = ...,
254         sourceline: int | None = ...,
255         sourcepos: int | None = ...,
256         can_be_empty_element: bool | None = ...,
257         cdata_list_attributes: list[str] | None = ...,
258         preserve_whitespace_tags: list[str] | None = ...,
259         interesting_string_types: Type[NavigableString] | Tuple[Type[NavigableString], ...] | None = ...,
260     ) -> None: ...
261     parserClass: Type[BeautifulSoup] | None
262     def __copy__(self: Self) -> Self: ...
263     @property
264     def is_empty_element(self) -> bool: ...
265     isSelfClosing = is_empty_element
266     @property
267     def string(self) -> str | None: ...
268     @string.setter
269     def string(self, string: str) -> None: ...
270     DEFAULT_INTERESTING_STRING_TYPES: Tuple[Type[NavigableString], ...]
271     @property
272     def strings(self) -> Iterable[str]: ...
273     def decompose(self) -> None: ...
274     def clear(self, decompose: bool = ...) -> None: ...
275     def smooth(self) -> None: ...
276     def index(self, element: PageElement) -> int: ...
277     def get(self, key: str, default: str | list[str] | None = ...) -> str | list[str] | None: ...
278     def get_attribute_list(self, key: str, default: str | list[str] | None = ...) -> list[str]: ...
279     def has_attr(self, key: str) -> bool: ...
280     def __hash__(self) -> int: ...
281     def __getitem__(self, key: str) -> str | list[str]: ...
282     def __iter__(self) -> Iterable[PageElement]: ...
283     def __len__(self) -> int: ...
284     def __contains__(self, x: object) -> bool: ...
285     def __bool__(self) -> bool: ...
286     def __setitem__(self, key: str, value: str | list[str]) -> None: ...
287     def __delitem__(self, key: str) -> None: ...
288     def __getattr__(self, tag: str) -> Tag | None: ...
289     def __eq__(self, other: object) -> bool: ...
290     def __ne__(self, other: object) -> bool: ...
291     def __unicode__(self) -> str: ...
292     def encode(
293         self, encoding: str = ..., indent_level: int | None = ..., formatter: str | Formatter = ..., errors: str = ...
294     ) -> bytes: ...
295     def decode(self, indent_level: int | None = ..., eventual_encoding: str = ..., formatter: str | Formatter = ...) -> str: ...
296     @overload
297     def prettify(self, encoding: str, formatter: str | Formatter = ...) -> bytes: ...
298     @overload
299     def prettify(self, encoding: None = ..., formatter: str | Formatter = ...) -> str: ...
300     def decode_contents(
301         self, indent_level: int | None = ..., eventual_encoding: str = ..., formatter: str | Formatter = ...
302     ) -> str: ...
303     def encode_contents(self, indent_level: int | None = ..., encoding: str = ..., formatter: str | Formatter = ...) -> bytes: ...
304     def renderContents(self, encoding: str = ..., prettyPrint: bool = ..., indentLevel: int = ...) -> bytes: ...
305     def find(
306         self,
307         name: _Strainable | None = ...,
308         attrs: dict[str, _Strainable] | _Strainable = ...,
309         recursive: bool = ...,
310         text: _Strainable | None = ...,
311         **kwargs: _Strainable,
312     ) -> Tag | NavigableString | None: ...
313     findChild = find
314     def find_all(
315         self,
316         name: _Strainable | None = ...,
317         attrs: dict[str, _Strainable] | _Strainable = ...,
318         recursive: bool = ...,
319         text: _Strainable | None = ...,
320         limit: int | None = ...,
321         **kwargs: _Strainable,
322     ) -> ResultSet[Any]: ...
323     __call__ = find_all
324     findAll = find_all
325     findChildren = find_all
326     @property
327     def children(self) -> Iterable[PageElement]: ...
328     @property
329     def descendants(self) -> Iterable[PageElement]: ...
330     def select_one(self, selector: str, namespaces: Any | None = ..., **kwargs) -> Tag | None: ...
331     def select(self, selector: str, namespaces: Any | None = ..., limit: int | None = ..., **kwargs) -> ResultSet[Tag]: ...
332     def childGenerator(self) -> Iterable[PageElement]: ...
333     def recursiveChildGenerator(self) -> Iterable[PageElement]: ...
334     def has_key(self, key: str) -> bool: ...
335
336 class SoupStrainer:
337     name: _NormalizedStrainable
338     attrs: dict[str, _NormalizedStrainable]
339     text: _NormalizedStrainable
340     def __init__(
341         self,
342         name: _Strainable | None = ...,
343         attrs: dict[str, _Strainable] | _Strainable = ...,
344         text: _Strainable | None = ...,
345         **kwargs: _Strainable,
346     ) -> None: ...
347     def search_tag(self, markup_name: Tag | str | None = ..., markup_attrs=...): ...
348     searchTag = search_tag
349     def search(self, markup: PageElement | Iterable[PageElement]): ...
350
351 class ResultSet(List[_PageElementT], Generic[_PageElementT]):
352     source: SoupStrainer
353     def __init__(self, source: SoupStrainer, result: Iterable[_PageElementT] = ...) -> None: ...