Add stubs for bleach (#2709)

* Add stubs for bleach

* Support Python 2 for bleach

* Add missing imports
This commit is contained in:
Sebastian Rittau
2019-03-11 05:08:46 +01:00
committed by Jelle Zijlstra
parent 012901e318
commit 6f00053511
5 changed files with 108 additions and 0 deletions

29
third_party/2and3/bleach/__init__.pyi vendored Normal file
View File

@@ -0,0 +1,29 @@
from typing import List, Any, Optional, Text
from bleach.linkifier import DEFAULT_CALLBACKS as DEFAULT_CALLBACKS, Linker as Linker
from bleach.sanitizer import (
ALLOWED_ATTRIBUTES as ALLOWED_ATTRIBUTES,
ALLOWED_PROTOCOLS as ALLOWED_PROTOCOLS,
ALLOWED_STYLES as ALLOWED_STYLES,
ALLOWED_TAGS as ALLOWED_TAGS,
Cleaner as Clear,
)
from .linkifier import _Callback
__releasedate__: Text
__version__: Text
VERSION: Any # packaging.version.Version
def clean(
text: Text,
tags: List[Text] = ...,
attributes: Any = ...,
styles: List[Text] = ...,
protocols: List[Text] = ...,
strip: bool = ...,
strip_comments: bool = ...,
) -> Text: ...
def linkify(
text: Text, callbacks: List[_Callback] = ..., skip_tags: Optional[List[Text]] = ..., parse_email: bool = ...
) -> Text: ...

View File

@@ -0,0 +1,6 @@
from typing import MutableMapping, Any, Text
_Attrs = MutableMapping[Any, Text]
def nofollow(attrs: _Attrs, new: bool = ...) -> _Attrs: ...
def target_blank(attrs: _Attrs, new: bool = ...) -> _Attrs: ...

30
third_party/2and3/bleach/linkifier.pyi vendored Normal file
View File

@@ -0,0 +1,30 @@
from typing import Any, List, MutableMapping, Protocol, Pattern, Iterable, Optional, Text
_Attrs = MutableMapping[Any, Text]
class _Callback(Protocol):
def __call__(self, attrs: _Attrs, new: bool = ...) -> _Attrs: ...
DEFAULT_CALLBACKS: List[_Callback]
TLDS: List[Text]
def build_url_re(tlds: Iterable[Text] = ..., protocols: Iterable[Text] = ...) -> Pattern[Text]: ...
URL_RE: Pattern[Text]
PHOTO_RE: Pattern[Text]
EMAIL_RE: Pattern[Text]
class Linker(object):
def __init__(
self,
callbacks: List[_Callback] = ...,
skip_tags: Optional[List[Text]] = ...,
parse_email: bool = ...,
url_re: Pattern[Text] = ...,
email_re: Pattern[Text] = ...,
) -> None: ...
def linkify(self, text: Text) -> Text: ...
class LinkifyFilter(object): # TODO: derives from html5lib.Filter
def __getattr__(self, item: str) -> Any: ... # incomplete

35
third_party/2and3/bleach/sanitizer.pyi vendored Normal file
View File

@@ -0,0 +1,35 @@
from typing import List, Dict, Any, Optional, Type, Pattern, Union, Callable, Container, Text
ALLOWED_TAGS: List[Text]
ALLOWED_ATTRIBUTES: Dict[Text, List[Text]]
ALLOWED_STYLES: List[Text]
ALLOWED_PROTOCOLS: List[Text]
INVISIBLE_CHARACTERS: Text
INVISIBLE_CHARACTERS_RE: Pattern[Text]
INVISIBLE_REPLACEMENT_CHAR: Text
# A html5lib Filter class
_Filter = Any
class Cleaner(object):
def __init__(
self,
tags: List[Text] = ...,
attributes: Any = ...,
styles: List[Text] = ...,
protocols: List[Text] = ...,
strip: bool = ...,
strip_comments: bool = ...,
filters: Optional[List[Type[_Filter]]] = ...,
) -> None: ...
def clean(self, text: Text) -> Text: ...
_AttributeFilter = Callable[[Text, Text, Text], bool]
_AttributeDict = Dict[Text, Union[Container[Text], _AttributeFilter]]
def attribute_filter_factory(attributes: Union[_AttributeFilter, _AttributeDict, List[Text]]) -> _AttributeFilter: ...
class BleachSanitizerFilter(object): # TODO: derives from html5lib.sanitizer.Filter
def __getattr__(self, item: str) -> Any: ... # incomplete

8
third_party/2and3/bleach/utils.pyi vendored Normal file
View File

@@ -0,0 +1,8 @@
from collections import OrderedDict
from typing import overload, Mapping, Any, Text
@overload
def alphabetize_attributes(attrs: None) -> None: ...
@overload
def alphabetize_attributes(attrs: Mapping[Any, Text]) -> OrderedDict[Any, Text]: ...
def force_unicode(text: Text) -> Text: ...