1 from collections.abc import Callable, Container, Iterable
2 from typing import Any, Dict, List, Pattern, Union
4 from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter
6 ALLOWED_TAGS: list[str]
7 ALLOWED_ATTRIBUTES: dict[str, list[str]]
8 ALLOWED_STYLES: list[str]
9 ALLOWED_PROTOCOLS: list[str]
11 INVISIBLE_CHARACTERS: str
12 INVISIBLE_CHARACTERS_RE: Pattern[str]
13 INVISIBLE_REPLACEMENT_CHAR: str
15 # A html5lib Filter class
18 class Cleaner(object):
20 attributes: _Attributes
21 styles: Container[str]
22 protocols: Container[str]
25 filters: Iterable[_Filter]
26 parser: BleachHTMLParser
28 serializer: BleachHTMLSerializer
31 tags: Container[str] = ...,
32 attributes: _Attributes = ...,
33 styles: Container[str] = ...,
34 protocols: Container[str] = ...,
36 strip_comments: bool = ...,
37 filters: Iterable[_Filter] | None = ...,
39 def clean(self, text: str) -> str: ...
41 _AttributeFilter = Callable[[str, str, str], bool]
42 _AttributeDict = Union[Dict[str, Union[List[str], _AttributeFilter]], Dict[str, List[str]], Dict[str, _AttributeFilter]]
43 _Attributes = Union[_AttributeFilter, _AttributeDict, List[str]]
45 def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ...
47 class BleachSanitizerFilter(SanitizerFilter):
48 attr_filter: _AttributeFilter
49 strip_disallowed_elements: bool
50 strip_html_comments: bool
54 attributes: _Attributes = ...,
55 strip_disallowed_elements: bool = ...,
56 strip_html_comments: bool = ...,
59 def sanitize_stream(self, token_iterator): ...
60 def merge_characters(self, token_iterator): ...
61 def __iter__(self): ...
62 def sanitize_token(self, token): ...
63 def sanitize_characters(self, token): ...
64 def sanitize_uri_value(self, value, allowed_protocols): ...
65 def allow_token(self, token): ...
66 def disallowed_token(self, token): ...
67 def sanitize_css(self, style): ...