Upgrade bleach stubs for 6.0 (#9583)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Sebastian Rittau
2023-01-24 16:46:34 +01:00
committed by GitHub
parent 307aadc632
commit 4148a7b73e
5 changed files with 73 additions and 44 deletions

View File

@@ -1 +1 @@
version = "5.0.*"
version = "6.0.*"

View File

@@ -1,7 +1,9 @@
from collections.abc import Container, Iterable
from typing_extensions import TypeAlias
from .callbacks import _Callback
from .css_sanitizer import CSSSanitizer
from .linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker, _Callback
from .linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker
from .sanitizer import (
ALLOWED_ATTRIBUTES as ALLOWED_ATTRIBUTES,
ALLOWED_PROTOCOLS as ALLOWED_PROTOCOLS,
@@ -15,11 +17,13 @@ __all__ = ["clean", "linkify"]
__releasedate__: str
__version__: str
_HTMLAttrKey: TypeAlias = tuple[str | None, str] # noqa: Y047
def clean(
text: str,
tags: Container[str] = ...,
tags: Iterable[str] = ...,
attributes: _Attributes = ...,
protocols: Container[str] = ...,
protocols: Iterable[str] = ...,
strip: bool = ...,
strip_comments: bool = ...,
css_sanitizer: CSSSanitizer | None = ...,

View File

@@ -1,8 +1,13 @@
from collections.abc import MutableMapping
from typing import Any
from typing import Protocol
from typing_extensions import TypeAlias
_Attrs: TypeAlias = MutableMapping[Any, str]
from bleach import _HTMLAttrKey
def nofollow(attrs: _Attrs, new: bool = ...) -> _Attrs: ...
def target_blank(attrs: _Attrs, new: bool = ...) -> _Attrs: ...
_HTMLAttrs: TypeAlias = MutableMapping[_HTMLAttrKey, str]
class _Callback(Protocol): # noqa: Y046
def __call__(self, attrs: _HTMLAttrs, new: bool = ...) -> _HTMLAttrs: ...
def nofollow(attrs: _HTMLAttrs, new: bool = ...) -> _HTMLAttrs: ...
def target_blank(attrs: _HTMLAttrs, new: bool = ...) -> _HTMLAttrs: ...

View File

@@ -1,16 +1,10 @@
from _typeshed import Incomplete
from collections.abc import Container, Iterable, MutableMapping
from collections.abc import Container, Iterable, Iterator
from re import Pattern
from typing import Any, Protocol
from typing_extensions import TypeAlias
from .callbacks import _Callback
from .html5lib_shim import Filter
_Attrs: TypeAlias = MutableMapping[Any, str]
class _Callback(Protocol):
def __call__(self, attrs: _Attrs, new: bool = ...) -> _Attrs: ...
DEFAULT_CALLBACKS: list[_Callback]
TLDS: list[str]
@@ -28,8 +22,8 @@ class Linker:
def __init__(
self,
callbacks: Iterable[_Callback] = ...,
skip_tags: Container[str] | None = ...,
parse_email: bool = ...,
skip_tags: Container[str] | None = None,
parse_email: bool = False,
url_re: Pattern[str] = ...,
email_re: Pattern[str] = ...,
recognized_tags: Container[str] | None = ...,
@@ -37,12 +31,25 @@ class Linker:
def linkify(self, text: str) -> str: ...
class LinkifyFilter(Filter):
callbacks: Any
callbacks: Iterable[_Callback]
skip_tags: Container[str]
parse_email: bool
url_re: Any
email_re: Any
url_re: Pattern[str]
email_re: Pattern[str]
def __init__(
self, source, callbacks=..., skip_tags: Container[str] | None = ..., parse_email: bool = ..., url_re=..., email_re=...
self,
source,
callbacks: Iterable[_Callback] | None = ...,
skip_tags: Container[str] | None = None,
parse_email: bool = False,
url_re: Pattern[str] = ...,
email_re: Pattern[str] = ...,
) -> None: ...
def __getattr__(self, item: str) -> Incomplete: ...
def apply_callbacks(self, attrs, is_new): ...
def extract_character_data(self, token_list): ...
def handle_email_addresses(self, src_iter): ...
def strip_non_url_bits(self, fragment): ...
def handle_links(self, src_iter): ...
def handle_a_tag(self, token_buffer): ...
def extract_entities(self, token): ...
def __iter__(self) -> Iterator[Incomplete]: ...

View File

@@ -1,38 +1,47 @@
from collections.abc import Callable, Container, Iterable
from _typeshed import Incomplete
from collections.abc import Callable, Iterable
from re import Pattern
from typing import Any
from typing import Protocol
from typing_extensions import TypeAlias
from . import _HTMLAttrKey
from .css_sanitizer import CSSSanitizer
from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter
ALLOWED_TAGS: list[str]
ALLOWED_TAGS: frozenset[str]
ALLOWED_ATTRIBUTES: dict[str, list[str]]
ALLOWED_PROTOCOLS: list[str]
ALLOWED_PROTOCOLS: frozenset[str]
INVISIBLE_CHARACTERS: str
INVISIBLE_CHARACTERS_RE: Pattern[str]
INVISIBLE_REPLACEMENT_CHAR: str
# A html5lib Filter class
_Filter: TypeAlias = Any
class _Filter(Protocol):
def __call__(self, *, source: BleachSanitizerFilter) -> Incomplete: ...
_AttributeFilter: TypeAlias = Callable[[str, str, str], bool]
_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter]
_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str]
_TreeWalker: TypeAlias = Callable[[Incomplete], Incomplete]
class Cleaner:
tags: Container[str]
tags: Iterable[str]
attributes: _Attributes
protocols: Container[str]
protocols: Iterable[str]
strip: bool
strip_comments: bool
filters: Iterable[_Filter]
css_sanitizer: CSSSanitizer | None
parser: BleachHTMLParser
walker: Any
walker: _TreeWalker
serializer: BleachHTMLSerializer
def __init__(
self,
tags: Container[str] = ...,
tags: Iterable[str] = ...,
attributes: _Attributes = ...,
protocols: Container[str] = ...,
protocols: Iterable[str] = ...,
strip: bool = ...,
strip_comments: bool = ...,
filters: Iterable[_Filter] | None = ...,
@@ -40,26 +49,30 @@ class Cleaner:
) -> None: ...
def clean(self, text: str) -> str: ...
_AttributeFilter: TypeAlias = Callable[[str, str, str], bool]
_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter]
_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str]
def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ...
class BleachSanitizerFilter(SanitizerFilter):
allowed_tags: frozenset[str]
allowed_protocols: frozenset[str]
attr_filter: _AttributeFilter
strip_disallowed_elements: bool
strip_disallowed_tags: bool
strip_html_comments: bool
attr_val_is_uri: frozenset[_HTMLAttrKey]
svg_attr_val_allows_ref: frozenset[_HTMLAttrKey]
svg_allow_local_href: frozenset[_HTMLAttrKey]
css_sanitizer: CSSSanitizer | None
def __init__(
self,
source,
allowed_elements: Container[str] = ...,
allowed_tags: Iterable[str] = ...,
attributes: _Attributes = ...,
allowed_protocols: Container[str] = ...,
strip_disallowed_elements: bool = ...,
strip_html_comments: bool = ...,
css_sanitizer: CSSSanitizer | None = ...,
**kwargs,
allowed_protocols: Iterable[str] = ...,
attr_val_is_uri: frozenset[_HTMLAttrKey] = ...,
svg_attr_val_allows_ref: frozenset[_HTMLAttrKey] = ...,
svg_allow_local_href: frozenset[_HTMLAttrKey] = ...,
strip_disallowed_tags: bool = False,
strip_html_comments: bool = True,
css_sanitizer: CSSSanitizer | None = None,
) -> None: ...
def sanitize_stream(self, token_iterator): ...
def merge_characters(self, token_iterator): ...