|
1 | | -from collections.abc import Callable, Container, Iterable |
| 1 | +from _typeshed import Incomplete |
| 2 | +from collections.abc import Callable, Iterable |
2 | 3 | from re import Pattern |
3 | | -from typing import Any |
| 4 | +from typing import Protocol |
4 | 5 | from typing_extensions import TypeAlias |
5 | 6 |
|
| 7 | +from . import _HTMLAttrKey |
6 | 8 | from .css_sanitizer import CSSSanitizer |
7 | 9 | from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter |
8 | 10 |
|
9 | | -ALLOWED_TAGS: list[str] |
| 11 | +ALLOWED_TAGS: frozenset[str] |
10 | 12 | ALLOWED_ATTRIBUTES: dict[str, list[str]] |
11 | | -ALLOWED_PROTOCOLS: list[str] |
| 13 | +ALLOWED_PROTOCOLS: frozenset[str] |
12 | 14 |
|
13 | 15 | INVISIBLE_CHARACTERS: str |
14 | 16 | INVISIBLE_CHARACTERS_RE: Pattern[str] |
15 | 17 | INVISIBLE_REPLACEMENT_CHAR: str |
16 | 18 |
|
17 | 19 | # A html5lib Filter class |
18 | | -_Filter: TypeAlias = Any |
| 20 | +class _Filter(Protocol): |
| 21 | + def __call__(self, *, source: BleachSanitizerFilter) -> Incomplete: ... |
| 22 | + |
| 23 | +_AttributeFilter: TypeAlias = Callable[[str, str, str], bool] |
| 24 | +_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] |
| 25 | +_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str] |
| 26 | + |
| 27 | +_TreeWalker: TypeAlias = Callable[[Incomplete], Incomplete] |
19 | 28 |
|
20 | 29 | class Cleaner: |
21 | | - tags: Container[str] |
| 30 | + tags: Iterable[str] |
22 | 31 | attributes: _Attributes |
23 | | - protocols: Container[str] |
| 32 | + protocols: Iterable[str] |
24 | 33 | strip: bool |
25 | 34 | strip_comments: bool |
26 | 35 | filters: Iterable[_Filter] |
27 | 36 | css_sanitizer: CSSSanitizer | None |
28 | 37 | parser: BleachHTMLParser |
29 | | - walker: Any |
| 38 | + walker: _TreeWalker |
30 | 39 | serializer: BleachHTMLSerializer |
31 | 40 | def __init__( |
32 | 41 | self, |
33 | | - tags: Container[str] = ..., |
| 42 | + tags: Iterable[str] = ..., |
34 | 43 | attributes: _Attributes = ..., |
35 | | - protocols: Container[str] = ..., |
| 44 | + protocols: Iterable[str] = ..., |
36 | 45 | strip: bool = ..., |
37 | 46 | strip_comments: bool = ..., |
38 | 47 | filters: Iterable[_Filter] | None = ..., |
39 | 48 | css_sanitizer: CSSSanitizer | None = ..., |
40 | 49 | ) -> None: ... |
41 | 50 | def clean(self, text: str) -> str: ... |
42 | 51 |
|
43 | | -_AttributeFilter: TypeAlias = Callable[[str, str, str], bool] |
44 | | -_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] |
45 | | -_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str] |
46 | | - |
47 | 52 | def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ... |
48 | 53 |
|
49 | 54 | class BleachSanitizerFilter(SanitizerFilter): |
| 55 | + allowed_tags: frozenset[str] |
| 56 | + allowed_protocols: frozenset[str] |
50 | 57 | attr_filter: _AttributeFilter |
51 | | - strip_disallowed_elements: bool |
| 58 | + strip_disallowed_tags: bool |
52 | 59 | strip_html_comments: bool |
| 60 | + attr_val_is_uri: frozenset[_HTMLAttrKey] |
| 61 | + svg_attr_val_allows_ref: frozenset[_HTMLAttrKey] |
| 62 | + svg_allow_local_href: frozenset[_HTMLAttrKey] |
| 63 | + css_sanitizer: CSSSanitizer | None |
53 | 64 | def __init__( |
54 | 65 | self, |
55 | 66 | source, |
56 | | - allowed_elements: Container[str] = ..., |
| 67 | + allowed_tags: Iterable[str] = ..., |
57 | 68 | attributes: _Attributes = ..., |
58 | | - allowed_protocols: Container[str] = ..., |
59 | | - strip_disallowed_elements: bool = ..., |
60 | | - strip_html_comments: bool = ..., |
61 | | - css_sanitizer: CSSSanitizer | None = ..., |
62 | | - **kwargs, |
| 69 | + allowed_protocols: Iterable[str] = ..., |
| 70 | + attr_val_is_uri: frozenset[_HTMLAttrKey] = ..., |
| 71 | + svg_attr_val_allows_ref: frozenset[_HTMLAttrKey] = ..., |
| 72 | + svg_allow_local_href: frozenset[_HTMLAttrKey] = ..., |
| 73 | + strip_disallowed_tags: bool = False, |
| 74 | + strip_html_comments: bool = True, |
| 75 | + css_sanitizer: CSSSanitizer | None = None, |
63 | 76 | ) -> None: ... |
64 | 77 | def sanitize_stream(self, token_iterator): ... |
65 | 78 | def merge_characters(self, token_iterator): ... |
|
0 commit comments