1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
# !/usr/bin/env python
#
# __init__.pyi
#
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
#
# Based on https://treyhunner.com/2013/09/singledispatch-json-serializer/
# Copyright © 2013 Trey Hunner
# He said "Feel free to use it however you like." So I have.
#
# Also based on the `json` module (version 2.0.9) by Bob Ippolito from Python 3.7
# Licensed under the Python Software Foundation License Version 2.
# Copyright © 2001-2020 Python Software Foundation. All rights reserved.
# Copyright © 2000 BeOpen.com. All rights reserved.
# Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
# Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.
#
# Type annotations from Typeshed
# https://github.com/python/typeshed
# Apache 2.0 Licensed
#
# stdlib
import json
from typing import (
IO,
Any,
Callable,
Dict,
Iterator,
List,
Mapping,
Optional,
Tuple,
Type,
TypeVar,
Union,
overload
)
# 3rd party
from typing_extensions import Protocol
__author__: str
__copyright__: str
__license__: str
__version__: str
__email__: str
_T_co = TypeVar("_T_co", covariant=True)
_LoadsString = Union[str, bytes]
_T = TypeVar("_T")
class SingleDispatch(Protocol):
"""
:class:`~typing.Protocol` representing a function decorated with :func:`functools.singledispatch`.
"""
@overload
def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
@overload
def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ...
def dispatch(self, cls: Any) -> Callable[..., _T]: ...
def unregister(self, cls: Type) -> Any: ...
registry: Mapping[Any, Callable[..., _T]]
def _clear_cache(self) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
class SupportsRead(Protocol[_T_co]):
def read(self, __length: int = ...) -> _T_co: ...
def allow_unregister(func: SingleDispatch) -> SingleDispatch: ...
def sphinxify_json_docstring() -> Callable: ...
class _Encoders:
_registry: SingleDispatch
_protocol_registry: Mapping[Any, Callable[..., _T]]
registry: Mapping[Any, Callable[..., _T]]
@overload
def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
@overload
def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ...
def dispatch(self, cls: Any) -> Callable[..., _T]: ...
def unregister(self, cls: Type, allow_missing: bool = ...) -> None: ...
encoders = _Encoders()
register_encoder = encoders.register
unregister_encoder = encoders.unregister
def dump(
obj: Any,
fp: IO[str],
*,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
cls: Optional[Type[json.JSONEncoder]] = ...,
indent: Union[None, int, str] = ...,
separators: Optional[Tuple[str, str]] = ...,
default: Optional[Callable[[Any], Any]] = ...,
sort_keys: bool = ...,
**kwargs: Any
) -> None: ...
def dumps(
obj: Any,
*,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
cls: Optional[Type[json.JSONEncoder]] = ...,
indent: Union[None, int, str] = ...,
separators: Optional[Tuple[str, str]] = ...,
default: Optional[Callable[[Any], Any]] = ...,
sort_keys: bool = ...,
**kwargs: Any
) -> str: ...
def loads(
s: _LoadsString,
*,
cls: Optional[Type[json.JSONDecoder]] = ...,
object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ...,
parse_float: Optional[Callable[[str], Any]] = ...,
parse_int: Optional[Callable[[str], Any]] = ...,
parse_constant: Optional[Callable[[str], Any]] = ...,
object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ...,
**kwargs: Any
) -> Any: ...
def load(
fp: SupportsRead[_LoadsString],
*,
cls: Optional[Type[json.JSONDecoder]] = ...,
object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ...,
parse_float: Optional[Callable[[str], Any]] = ...,
parse_int: Optional[Callable[[str], Any]] = ...,
parse_constant: Optional[Callable[[str], Any]] = ...,
object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ...,
**kwargs: Any
) -> Any: ...
class JSONEncoder(json.JSONEncoder):
def __init__(
self,
*,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
sort_keys: bool = ...,
indent: Optional[int] = ...,
separators: Optional[Tuple[str, str]] = ...,
default: Optional[Callable[..., Any]] = ...
) -> None: ...
def default(self, o: Any) -> Any: ...
def encode(self, o: Any) -> str: ...
def iterencode(self, o: Any, _one_shot: bool = ...) -> Iterator[str]: ...
class JSONDecoder(json.JSONDecoder):
object_hook: Callable[[Dict[str, Any]], Any]
parse_float: Callable[[str], Any]
parse_int: Callable[[str], Any]
parse_constant: Callable[[str], Any] = ...
strict: bool
object_pairs_hook: Callable[[List[Tuple[str, Any]]], Any]
parse_object: Callable[[str], Any]
parse_array: Callable[[str], Any]
parse_string: Callable[[str], Any]
memo: Dict
scan_once: Any
def __init__(
self,
*,
object_hook: Optional[Callable[[Dict[str, Any]], Any]] = ...,
parse_float: Optional[Callable[[str], Any]] = ...,
parse_int: Optional[Callable[[str], Any]] = ...,
parse_constant: Optional[Callable[[str], Any]] = ...,
strict: bool = ...,
object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], Any]] = ...
) -> None: ...
def decode(self, s: str, _w: Callable[..., Any] = ...) -> Any: ... # _w is undocumented
def raw_decode(self, s: str, idx: int = ...) -> Tuple[Any, int]: ...
JSONDecodeError = json.JSONDecodeError
class _CustomEncoder(JSONEncoder): ...
_default_encoder = _CustomEncoder(
skipkeys=False,
ensure_ascii=True,
check_circular=True,
allow_nan=True,
indent=None,
separators=None,
default=None,
)
|