diff --git a/stubs/bleach/@tests/stubtest_allowlist.txt b/stubs/bleach/@tests/stubtest_allowlist.txt index 6189077db..c3ff453fd 100644 --- a/stubs/bleach/@tests/stubtest_allowlist.txt +++ b/stubs/bleach/@tests/stubtest_allowlist.txt @@ -1 +1,2 @@ +bleach.css_sanitizer # Requires tinycss2 to be installed bleach.html5lib_shim.* diff --git a/stubs/bleach/METADATA.toml b/stubs/bleach/METADATA.toml index bb8cc449b..c98db6304 100644 --- a/stubs/bleach/METADATA.toml +++ b/stubs/bleach/METADATA.toml @@ -1 +1 @@ -version = "4.1.*" +version = "5.0.*" diff --git a/stubs/bleach/bleach/__init__.pyi b/stubs/bleach/bleach/__init__.pyi index 202979e20..94186a545 100644 --- a/stubs/bleach/bleach/__init__.pyi +++ b/stubs/bleach/bleach/__init__.pyi @@ -1,11 +1,10 @@ from collections.abc import Container, Iterable -from typing import Any -from bleach.linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker, _Callback -from bleach.sanitizer import ( +from .css_sanitizer import CSSSanitizer +from .linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker, _Callback +from .sanitizer import ( ALLOWED_ATTRIBUTES as ALLOWED_ATTRIBUTES, ALLOWED_PROTOCOLS as ALLOWED_PROTOCOLS, - ALLOWED_STYLES as ALLOWED_STYLES, ALLOWED_TAGS as ALLOWED_TAGS, Cleaner as Cleaner, _Attributes, @@ -15,16 +14,15 @@ __all__ = ["clean", "linkify"] __releasedate__: str __version__: str -VERSION: Any # packaging.version.Version def clean( text: str, tags: Container[str] = ..., attributes: _Attributes = ..., - styles: Container[str] = ..., protocols: Container[str] = ..., strip: bool = ..., strip_comments: bool = ..., + css_sanitizer: CSSSanitizer | None = ..., ) -> str: ... def linkify( text: str, callbacks: Iterable[_Callback] = ..., skip_tags: Container[str] | None = ..., parse_email: bool = ... diff --git a/stubs/bleach/bleach/css_sanitizer.pyi b/stubs/bleach/bleach/css_sanitizer.pyi new file mode 100644 index 000000000..5e3c6f2ba --- /dev/null +++ b/stubs/bleach/bleach/css_sanitizer.pyi @@ -0,0 +1,11 @@ +from collections.abc import Container + +ALLOWED_CSS_PROPERTIES: frozenset[str] +ALLOWED_SVG_PROPERTIES: frozenset[str] + +class CSSSanitizer: + allowed_css_properties: Container[str] + allowed_svg_properties: Container[str] + + def __init__(self, allowed_css_properties: Container[str] = ..., allowed_svg_properties: Container[str] = ...) -> None: ... + def sanitize_css(self, style: str) -> str: ... diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 5d6f3552a..9e550a76d 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,11 +1,11 @@ from collections.abc import Callable, Container, Iterable from typing import Any, Pattern +from .css_sanitizer import CSSSanitizer from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter ALLOWED_TAGS: list[str] ALLOWED_ATTRIBUTES: dict[str, list[str]] -ALLOWED_STYLES: list[str] ALLOWED_PROTOCOLS: list[str] INVISIBLE_CHARACTERS: str @@ -18,11 +18,11 @@ _Filter = Any class Cleaner: tags: Container[str] attributes: _Attributes - styles: Container[str] protocols: Container[str] strip: bool strip_comments: bool filters: Iterable[_Filter] + css_sanitizer: CSSSanitizer | None parser: BleachHTMLParser walker: Any serializer: BleachHTMLSerializer @@ -30,11 +30,11 @@ class Cleaner: self, tags: Container[str] = ..., attributes: _Attributes = ..., - styles: Container[str] = ..., protocols: Container[str] = ..., strip: bool = ..., strip_comments: bool = ..., filters: Iterable[_Filter] | None = ..., + css_sanitizer: CSSSanitizer | None = ..., ) -> None: ... def clean(self, text: str) -> str: ... @@ -51,9 +51,12 @@ class BleachSanitizerFilter(SanitizerFilter): def __init__( self, source, + allowed_elements: Container[str] = ..., attributes: _Attributes = ..., + allowed_protocols: Container[str] = ..., strip_disallowed_elements: bool = ..., strip_html_comments: bool = ..., + css_sanitizer: CSSSanitizer | None = ..., **kwargs, ) -> None: ... def sanitize_stream(self, token_iterator): ... diff --git a/stubs/bleach/bleach/utils.pyi b/stubs/bleach/bleach/utils.pyi deleted file mode 100644 index 1eff440f0..000000000 --- a/stubs/bleach/bleach/utils.pyi +++ /dev/null @@ -1,8 +0,0 @@ -from collections import OrderedDict -from collections.abc import Mapping -from typing import Any, overload - -@overload -def alphabetize_attributes(attrs: None) -> None: ... -@overload -def alphabetize_attributes(attrs: Mapping[Any, str]) -> OrderedDict[Any, str]: ...