diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 4d84e8dfe..faea8515f 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -26,6 +26,7 @@ "stdlib/xml/sax", "stubs/backports", "stubs/backports_abc", + "stubs/bleach", "stubs/boto", "stubs/cryptography", "stubs/docutils", diff --git a/stubs/bleach/@tests/stubtest_allowlist.txt b/stubs/bleach/@tests/stubtest_allowlist.txt index bd4011f2f..6189077db 100644 --- a/stubs/bleach/@tests/stubtest_allowlist.txt +++ b/stubs/bleach/@tests/stubtest_allowlist.txt @@ -1,2 +1 @@ -bleach.linkifier.LinkifyFilter.__init__ -bleach.sanitizer.BleachSanitizerFilter.__init__ +bleach.html5lib_shim.* diff --git a/stubs/bleach/METADATA.toml b/stubs/bleach/METADATA.toml index 31f638bf3..31383cdd6 100644 --- a/stubs/bleach/METADATA.toml +++ b/stubs/bleach/METADATA.toml @@ -1,2 +1,2 @@ -version = "0.1" +version = "3.3" python2 = true diff --git a/stubs/bleach/bleach/__init__.pyi b/stubs/bleach/bleach/__init__.pyi index 82af5aad0..ef0341e67 100644 --- a/stubs/bleach/bleach/__init__.pyi +++ b/stubs/bleach/bleach/__init__.pyi @@ -7,8 +7,11 @@ from bleach.sanitizer import ( ALLOWED_STYLES as ALLOWED_STYLES, ALLOWED_TAGS as ALLOWED_TAGS, Cleaner as Cleaner, + _Attributes, ) +__all__ = ["clean", "linkify"] + __releasedate__: Text __version__: Text VERSION: Any # packaging.version.Version @@ -16,7 +19,7 @@ VERSION: Any # packaging.version.Version def clean( text: Text, tags: Container[Text] = ..., - attributes: Any = ..., + attributes: _Attributes = ..., styles: Container[Text] = ..., protocols: Container[Text] = ..., strip: bool = ..., diff --git a/stubs/bleach/bleach/html5lib_shim.pyi b/stubs/bleach/bleach/html5lib_shim.pyi new file mode 100644 index 000000000..b9949db04 --- /dev/null +++ b/stubs/bleach/bleach/html5lib_shim.pyi @@ -0,0 +1,26 @@ +from typing import Any, Generator, Iterable, List, Optional, Text + +class HTMLParser(object): # actually html5lib.HTMLParser + def __getattr__(self, __name: Text) -> Any: ... # incomplete + +class Filter(object): # actually html5lib.filters.base.Filter + def __getattr__(self, __name: Text) -> Any: ... # incomplete + +class SanitizerFilter(object): # actually html5lib.filters.sanitizer.Filter + def __getattr__(self, __name: Text) -> Any: ... # incomplete + +class HTMLSerializer(object): # actually html5lib.serializer.HTMLSerializer + def __getattr__(self, __name: Text) -> Any: ... # incomplete + +class BleachHTMLParser(HTMLParser): + tags: Optional[List[Text]] + strip: bool + consume_entities: bool + def __init__(self, tags: Optional[Iterable[Text]], strip: bool, consume_entities: bool, **kwargs) -> None: ... + +class BleachHTMLSerializer(HTMLSerializer): + escape_rcdata: bool + def escape_base_amp(self, stoken: Text) -> Generator[Text, None, None]: ... + def serialize(self, treewalker, encoding: Optional[Text] = ...) -> Generator[Text, None, None]: ... + +def __getattr__(__name: Text) -> Any: ... # incomplete diff --git a/stubs/bleach/bleach/linkifier.pyi b/stubs/bleach/bleach/linkifier.pyi index f6ef3cea5..1e51b504c 100644 --- a/stubs/bleach/bleach/linkifier.pyi +++ b/stubs/bleach/bleach/linkifier.pyi @@ -1,5 +1,7 @@ from typing import Any, Container, Iterable, List, MutableMapping, Optional, Pattern, Protocol, Text +from .html5lib_shim import Filter + _Attrs = MutableMapping[Any, Text] class _Callback(Protocol): @@ -13,6 +15,9 @@ def build_url_re(tlds: Iterable[Text] = ..., protocols: Iterable[Text] = ...) -> URL_RE: Pattern[Text] PROTO_RE: Pattern[Text] + +def build_email_re(tlds: Iterable[Text] = ...) -> Pattern[Text]: ... + EMAIL_RE: Pattern[Text] class Linker(object): @@ -27,5 +32,13 @@ class Linker(object): ) -> None: ... def linkify(self, text: Text) -> Text: ... -class LinkifyFilter(object): # TODO: derives from html5lib.Filter - def __getattr__(self, item: str) -> Any: ... # incomplete +class LinkifyFilter(Filter): + callbacks: Any + skip_tags: Container[Text] + parse_email: bool + url_re: Any + email_re: Any + def __init__( + self, source, callbacks=..., skip_tags: Container[Text] | None = ..., parse_email: bool = ..., url_re=..., email_re=... + ) -> None: ... + def __getattr__(self, item: Text) -> Any: ... # incomplete diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 669d71891..bd5f69f89 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,5 +1,7 @@ from typing import Any, Callable, Container, Dict, Iterable, List, Optional, Pattern, Text, Union +from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter + ALLOWED_TAGS: List[Text] ALLOWED_ATTRIBUTES: Dict[Text, List[Text]] ALLOWED_STYLES: List[Text] @@ -13,10 +15,20 @@ INVISIBLE_REPLACEMENT_CHAR: Text _Filter = Any class Cleaner(object): + tags: Container[Text] + attributes: _Attributes + styles: Container[Text] + protocols: Container[Text] + strip: bool + strip_comments: bool + filters: Iterable[_Filter] + parser: BleachHTMLParser + walker: Any + serializer: BleachHTMLSerializer def __init__( self, tags: Container[Text] = ..., - attributes: Any = ..., + attributes: _Attributes = ..., styles: Container[Text] = ..., protocols: Container[Text] = ..., strip: bool = ..., @@ -27,8 +39,28 @@ class Cleaner(object): _AttributeFilter = Callable[[Text, Text, Text], bool] _AttributeDict = Dict[Text, Union[Container[Text], _AttributeFilter]] +_Attributes = Union[_AttributeFilter, _AttributeDict, List[Text]] -def attribute_filter_factory(attributes: Union[_AttributeFilter, _AttributeDict, Container[Text]]) -> _AttributeFilter: ... +def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ... -class BleachSanitizerFilter(object): # TODO: derives from html5lib.sanitizer.Filter - def __getattr__(self, item: str) -> Any: ... # incomplete +class BleachSanitizerFilter(SanitizerFilter): + attr_filter: _AttributeFilter + strip_disallowed_elements: bool + strip_html_comments: bool + def __init__( + self, + source, + attributes: _Attributes = ..., + strip_disallowed_elements: bool = ..., + strip_html_comments: bool = ..., + **kwargs, + ) -> None: ... + def sanitize_stream(self, token_iterator): ... + def merge_characters(self, token_iterator): ... + def __iter__(self): ... + def sanitize_token(self, token): ... + def sanitize_characters(self, token): ... + def sanitize_uri_value(self, value, allowed_protocols): ... + def allow_token(self, token): ... + def disallowed_token(self, token): ... + def sanitize_css(self, style): ...