Skip to content

Commit 9786596

Browse files
authored
Upgrade bleach version to 4 and drop Python 2 (#5897)
bleach 4 has no API changes, but dropped support for old Python versions.
1 parent 9af9cca commit 9786596

File tree

7 files changed

+65
-61
lines changed

7 files changed

+65
-61
lines changed

stubs/bleach/METADATA.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
version = "3.3"
2-
python2 = true
1+
version = "4.0"

stubs/bleach/bleach/__init__.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Container, Iterable, Text
1+
from collections.abc import Container, Iterable
2+
from typing import Any
23

34
from bleach.linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker, _Callback
45
from bleach.sanitizer import (
@@ -12,19 +13,19 @@ from bleach.sanitizer import (
1213

1314
__all__ = ["clean", "linkify"]
1415

15-
__releasedate__: Text
16-
__version__: Text
16+
__releasedate__: str
17+
__version__: str
1718
VERSION: Any # packaging.version.Version
1819

1920
def clean(
20-
text: Text,
21-
tags: Container[Text] = ...,
21+
text: str,
22+
tags: Container[str] = ...,
2223
attributes: _Attributes = ...,
23-
styles: Container[Text] = ...,
24-
protocols: Container[Text] = ...,
24+
styles: Container[str] = ...,
25+
protocols: Container[str] = ...,
2526
strip: bool = ...,
2627
strip_comments: bool = ...,
27-
) -> Text: ...
28+
) -> str: ...
2829
def linkify(
29-
text: Text, callbacks: Iterable[_Callback] = ..., skip_tags: Container[Text] | None = ..., parse_email: bool = ...
30-
) -> Text: ...
30+
text: str, callbacks: Iterable[_Callback] = ..., skip_tags: Container[str] | None = ..., parse_email: bool = ...
31+
) -> str: ...

stubs/bleach/bleach/callbacks.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Any, MutableMapping, Text
1+
from collections.abc import MutableMapping
2+
from typing import Any
23

3-
_Attrs = MutableMapping[Any, Text]
4+
_Attrs = MutableMapping[Any, str]
45

56
def nofollow(attrs: _Attrs, new: bool = ...) -> _Attrs: ...
67
def target_blank(attrs: _Attrs, new: bool = ...) -> _Attrs: ...

stubs/bleach/bleach/html5lib_shim.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
from typing import Any, Generator, Iterable, Text
1+
from collections.abc import Generator, Iterable
2+
from typing import Any
23

34
class HTMLParser(object): # actually html5lib.HTMLParser
4-
def __getattr__(self, __name: Text) -> Any: ... # incomplete
5+
def __getattr__(self, __name: str) -> Any: ... # incomplete
56

67
class Filter(object): # actually html5lib.filters.base.Filter
7-
def __getattr__(self, __name: Text) -> Any: ... # incomplete
8+
def __getattr__(self, __name: str) -> Any: ... # incomplete
89

910
class SanitizerFilter(object): # actually html5lib.filters.sanitizer.Filter
10-
def __getattr__(self, __name: Text) -> Any: ... # incomplete
11+
def __getattr__(self, __name: str) -> Any: ... # incomplete
1112

1213
class HTMLSerializer(object): # actually html5lib.serializer.HTMLSerializer
13-
def __getattr__(self, __name: Text) -> Any: ... # incomplete
14+
def __getattr__(self, __name: str) -> Any: ... # incomplete
1415

1516
class BleachHTMLParser(HTMLParser):
16-
tags: list[Text] | None
17+
tags: list[str] | None
1718
strip: bool
1819
consume_entities: bool
19-
def __init__(self, tags: Iterable[Text] | None, strip: bool, consume_entities: bool, **kwargs) -> None: ...
20+
def __init__(self, tags: Iterable[str] | None, strip: bool, consume_entities: bool, **kwargs) -> None: ...
2021

2122
class BleachHTMLSerializer(HTMLSerializer):
2223
escape_rcdata: bool
23-
def escape_base_amp(self, stoken: Text) -> Generator[Text, None, None]: ...
24-
def serialize(self, treewalker, encoding: Text | None = ...) -> Generator[Text, None, None]: ...
24+
def escape_base_amp(self, stoken: str) -> Generator[str, None, None]: ...
25+
def serialize(self, treewalker, encoding: str | None = ...) -> Generator[str, None, None]: ...
2526

26-
def __getattr__(__name: Text) -> Any: ... # incomplete
27+
def __getattr__(__name: str) -> Any: ... # incomplete

stubs/bleach/bleach/linkifier.pyi

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
from typing import Any, Container, Iterable, MutableMapping, Pattern, Protocol, Text
1+
from collections.abc import Container, Iterable, MutableMapping
2+
from typing import Any, Pattern, Protocol
23

34
from .html5lib_shim import Filter
45

5-
_Attrs = MutableMapping[Any, Text]
6+
_Attrs = MutableMapping[Any, str]
67

78
class _Callback(Protocol):
89
def __call__(self, attrs: _Attrs, new: bool = ...) -> _Attrs: ...
910

1011
DEFAULT_CALLBACKS: list[_Callback]
1112

12-
TLDS: list[Text]
13+
TLDS: list[str]
1314

14-
def build_url_re(tlds: Iterable[Text] = ..., protocols: Iterable[Text] = ...) -> Pattern[Text]: ...
15+
def build_url_re(tlds: Iterable[str] = ..., protocols: Iterable[str] = ...) -> Pattern[str]: ...
1516

16-
URL_RE: Pattern[Text]
17-
PROTO_RE: Pattern[Text]
17+
URL_RE: Pattern[str]
18+
PROTO_RE: Pattern[str]
1819

19-
def build_email_re(tlds: Iterable[Text] = ...) -> Pattern[Text]: ...
20+
def build_email_re(tlds: Iterable[str] = ...) -> Pattern[str]: ...
2021

21-
EMAIL_RE: Pattern[Text]
22+
EMAIL_RE: Pattern[str]
2223

2324
class Linker(object):
2425
def __init__(
2526
self,
2627
callbacks: Iterable[_Callback] = ...,
27-
skip_tags: Container[Text] | None = ...,
28+
skip_tags: Container[str] | None = ...,
2829
parse_email: bool = ...,
29-
url_re: Pattern[Text] = ...,
30-
email_re: Pattern[Text] = ...,
31-
recognized_tags: Container[Text] | None = ...,
30+
url_re: Pattern[str] = ...,
31+
email_re: Pattern[str] = ...,
32+
recognized_tags: Container[str] | None = ...,
3233
) -> None: ...
33-
def linkify(self, text: Text) -> Text: ...
34+
def linkify(self, text: str) -> str: ...
3435

3536
class LinkifyFilter(Filter):
3637
callbacks: Any
37-
skip_tags: Container[Text]
38+
skip_tags: Container[str]
3839
parse_email: bool
3940
url_re: Any
4041
email_re: Any
4142
def __init__(
42-
self, source, callbacks=..., skip_tags: Container[Text] | None = ..., parse_email: bool = ..., url_re=..., email_re=...
43+
self, source, callbacks=..., skip_tags: Container[str] | None = ..., parse_email: bool = ..., url_re=..., email_re=...
4344
) -> None: ...
44-
def __getattr__(self, item: Text) -> Any: ... # incomplete
45+
def __getattr__(self, item: str) -> Any: ... # incomplete

stubs/bleach/bleach/sanitizer.pyi

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
from typing import Any, Callable, Container, Dict, Iterable, List, Pattern, Text, Union
1+
from collections.abc import Callable, Container, Iterable
2+
from typing import Any, Dict, List, Pattern, Union
23

34
from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter
45

5-
ALLOWED_TAGS: list[Text]
6-
ALLOWED_ATTRIBUTES: dict[Text, list[Text]]
7-
ALLOWED_STYLES: list[Text]
8-
ALLOWED_PROTOCOLS: list[Text]
6+
ALLOWED_TAGS: list[str]
7+
ALLOWED_ATTRIBUTES: dict[str, list[str]]
8+
ALLOWED_STYLES: list[str]
9+
ALLOWED_PROTOCOLS: list[str]
910

10-
INVISIBLE_CHARACTERS: Text
11-
INVISIBLE_CHARACTERS_RE: Pattern[Text]
12-
INVISIBLE_REPLACEMENT_CHAR: Text
11+
INVISIBLE_CHARACTERS: str
12+
INVISIBLE_CHARACTERS_RE: Pattern[str]
13+
INVISIBLE_REPLACEMENT_CHAR: str
1314

1415
# A html5lib Filter class
1516
_Filter = Any
1617

1718
class Cleaner(object):
18-
tags: Container[Text]
19+
tags: Container[str]
1920
attributes: _Attributes
20-
styles: Container[Text]
21-
protocols: Container[Text]
21+
styles: Container[str]
22+
protocols: Container[str]
2223
strip: bool
2324
strip_comments: bool
2425
filters: Iterable[_Filter]
@@ -27,19 +28,19 @@ class Cleaner(object):
2728
serializer: BleachHTMLSerializer
2829
def __init__(
2930
self,
30-
tags: Container[Text] = ...,
31+
tags: Container[str] = ...,
3132
attributes: _Attributes = ...,
32-
styles: Container[Text] = ...,
33-
protocols: Container[Text] = ...,
33+
styles: Container[str] = ...,
34+
protocols: Container[str] = ...,
3435
strip: bool = ...,
3536
strip_comments: bool = ...,
3637
filters: Iterable[_Filter] | None = ...,
3738
) -> None: ...
38-
def clean(self, text: Text) -> Text: ...
39+
def clean(self, text: str) -> str: ...
3940

40-
_AttributeFilter = Callable[[Text, Text, Text], bool]
41-
_AttributeDict = Union[Dict[Text, Union[List[Text], _AttributeFilter]], Dict[Text, List[Text]], Dict[Text, _AttributeFilter]]
42-
_Attributes = Union[_AttributeFilter, _AttributeDict, List[Text]]
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]]
4344

4445
def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ...
4546

stubs/bleach/bleach/utils.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections import OrderedDict
2-
from typing import Any, Mapping, Text, overload
2+
from collections.abc import Mapping
3+
from typing import Any, overload
34

4-
def force_unicode(text: Text) -> Text: ...
55
@overload
66
def alphabetize_attributes(attrs: None) -> None: ...
77
@overload
8-
def alphabetize_attributes(attrs: Mapping[Any, Text]) -> OrderedDict[Any, Text]: ...
8+
def alphabetize_attributes(attrs: Mapping[Any, str]) -> OrderedDict[Any, str]: ...

0 commit comments

Comments
 (0)