|
1 | | -from _typeshed import Incomplete |
| 1 | +import re |
| 2 | +from codecs import CodecInfo |
2 | 3 | from collections.abc import Generator, Iterable, Iterator |
| 4 | +from typing import Any, Final, Protocol |
3 | 5 |
|
4 | | -class HTMLParser: # actually html5lib.HTMLParser |
5 | | - def __getattr__(self, __name: str) -> Incomplete: ... |
| 6 | +# We don't re-export any `html5lib` types / values here, because they are not |
| 7 | +# really public and may change at any time. This is just a helper module, |
| 8 | +# import things directly from `html5lib` instead! |
| 9 | +from html5lib import HTMLParser |
| 10 | +from html5lib._inputstream import HTMLBinaryInputStream, HTMLUnicodeInputStream |
| 11 | +from html5lib._tokenizer import HTMLTokenizer |
| 12 | +from html5lib._trie import Trie |
| 13 | +from html5lib.serializer import HTMLSerializer |
| 14 | +from html5lib.treewalkers.base import TreeWalker |
6 | 15 |
|
7 | | -class Filter: # actually html5lib.filters.base.Filter |
8 | | - source: Incomplete |
9 | | - def __init__(self, source) -> None: ... |
10 | | - def __iter__(self) -> Iterator[Incomplete]: ... |
11 | | - def __getattr__(self, name: str) -> Incomplete: ... # copy attributes from source |
| 16 | +# Is actually webencodings.Encoding |
| 17 | +class _Encoding(Protocol): |
| 18 | + name: str |
| 19 | + codec_info: CodecInfo |
| 20 | + def __init__(self, name: str, codec_info: CodecInfo) -> None: ... |
12 | 21 |
|
13 | | -class SanitizerFilter: # actually html5lib.filters.sanitizer.Filter |
14 | | - def __getattr__(self, __name: str) -> Incomplete: ... |
| 22 | +HTML_TAGS: Final[frozenset[str]] |
| 23 | +HTML_TAGS_BLOCK_LEVEL: Final[frozenset[str]] |
| 24 | +AMP_SPLIT_RE: Final[re.Pattern[str]] |
| 25 | +ENTITIES: Final[dict[str, str]] |
| 26 | +ENTITIES_TRIE: Final[Trie] |
| 27 | +TAG_TOKEN_TYPES: Final[set[int]] |
| 28 | +TAG_TOKEN_TYPE_CHARACTERS: Final[int] |
| 29 | +TAG_TOKEN_TYPE_END: Final[int] |
| 30 | +TAG_TOKEN_TYPE_PARSEERROR: Final[int] |
| 31 | +TAG_TOKEN_TYPE_START: Final[int] |
15 | 32 |
|
16 | | -class HTMLSerializer: # actually html5lib.serializer.HTMLSerializer |
17 | | - def __getattr__(self, __name: str) -> Incomplete: ... |
| 33 | +class InputStreamWithMemory: |
| 34 | + position = HTMLUnicodeInputStream.position |
| 35 | + reset = HTMLUnicodeInputStream.reset |
| 36 | + def __init__(self, inner_stream: HTMLUnicodeInputStream) -> None: ... |
| 37 | + @property |
| 38 | + def errors(self) -> list[str]: ... |
| 39 | + @property |
| 40 | + def charEncoding(self) -> tuple[_Encoding, str]: ... |
| 41 | + # If inner_stream wasn't a HTMLBinaryInputStream, this will error at runtime |
| 42 | + # Is a property returning a method, simplified: |
| 43 | + changeEncoding = HTMLBinaryInputStream.changeEncoding |
| 44 | + def char(self) -> str: ... |
| 45 | + def charsUntil(self, characters: Iterable[str], opposite: bool = False) -> str: ... |
| 46 | + def unget(self, char: str | None) -> None: ... |
| 47 | + def get_tag(self) -> str: ... |
| 48 | + def start_tag(self) -> None: ... |
| 49 | + |
| 50 | +class BleachHTMLTokenizer(HTMLTokenizer): |
| 51 | + consume_entities: bool |
| 52 | + stream: InputStreamWithMemory |
| 53 | + emitted_last_token: dict[str, Any] | None |
| 54 | + def __init__(self, consume_entities: bool = False, **kwargs: Any) -> None: ... |
18 | 55 |
|
19 | 56 | class BleachHTMLParser(HTMLParser): |
20 | 57 | tags: list[str] | None |
21 | 58 | strip: bool |
22 | 59 | consume_entities: bool |
23 | | - def __init__(self, tags: Iterable[str] | None, strip: bool, consume_entities: bool, **kwargs) -> None: ... |
| 60 | + def __init__(self, tags: Iterable[str] | None, strip: bool, consume_entities: bool, **kwargs: Any) -> None: ... |
24 | 61 |
|
25 | 62 | class BleachHTMLSerializer(HTMLSerializer): |
26 | 63 | escape_rcdata: bool |
27 | 64 | def escape_base_amp(self, stoken: str) -> Generator[str, None, None]: ... |
28 | | - def serialize(self, treewalker, encoding: str | None = None) -> Generator[str, None, None]: ... |
| 65 | + def serialize(self, treewalker: TreeWalker, encoding: str | None = None) -> Generator[str, None, None]: ... # type: ignore[override] |
29 | 66 |
|
30 | | -def __getattr__(__name: str) -> Incomplete: ... |
| 67 | +def convert_entity(value: str) -> str | None: ... |
| 68 | +def convert_entities(text: str) -> str: ... |
| 69 | +def match_entity(stream: str) -> str | None: ... |
| 70 | +def next_possible_entity(text: str) -> Iterator[str]: ... |
0 commit comments