1 from datetime import datetime
\r
2 from typing import Any, Callable, IO, MutableMapping, Optional, Text, Tuple, TypeVar, Union
\r
6 int_to_byte = Callable[[int], bytes]
\r
7 number_types = (int, float)
\r
10 _bytes_like = Union[bytearray, bytes]
\r
11 _str_like = Union[str, bytes]
\r
12 _can_become_bytes = Union[str, bytes, bytearray]
\r
13 _comparable_bytes = TypeVar('_comparable_bytes', str, _bytes_like)
\r
14 _serializer = Any # must be an object that has "dumps" and "loads" attributes (e.g. the json module)
\r
17 def loads(self, payload: Text) -> Any: ...
\r
18 def dumps(self, obj: Any) -> Text: ...
\r
20 compact_json = _CompactJSON
\r
21 EPOCH = ... # type: int
\r
23 def want_bytes(s: _can_become_bytes, encoding: str = ..., errors: str = ...) -> bytes: ...
\r
24 def is_text_serializer(serializer: _serializer) -> bool: ...
\r
25 def constant_time_compare(val1: _comparable_bytes, val2: _comparable_bytes) -> bool: ...
\r
27 class BadData(Exception):
\r
28 message = ... # type: str
\r
29 def __init__(self, message: str) -> None: ...
\r
31 class BadPayload(BadData):
\r
32 original_error = ... # type: Optional[Exception]
\r
33 def __init__(self, message: str, original_error: Optional[Exception] = ...) -> None: ...
\r
35 class BadSignature(BadData):
\r
36 payload = ... # type: Optional[Any]
\r
37 def __init__(self, message: str, payload: Optional[Any] = ...) -> None: ...
\r
39 class BadTimeSignature(BadSignature):
\r
40 date_signed = ... # type: Optional[int]
\r
41 def __init__(self, message: str, payload: Optional[Any] = ..., date_signed: Optional[int] = ...) -> None: ...
\r
43 class BadHeader(BadSignature):
\r
44 header = ... # type: Any
\r
45 original_error = ... # type: Any
\r
46 def __init__(self, message, payload=None, header=None, original_error=None) -> None: ...
\r
48 class SignatureExpired(BadTimeSignature): ...
\r
50 def base64_encode(string: _can_become_bytes) -> bytes: ...
\r
51 def base64_decode(string: _can_become_bytes) -> bytes: ...
\r
52 def int_to_bytes(num: int) -> bytes: ...
\r
53 def bytes_to_int(bytestr: _can_become_bytes) -> bytes: ...
\r
55 class SigningAlgorithm:
\r
56 def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ...
\r
57 def verify_signature(self, key: _bytes_like, value: _bytes_like, sig: _can_become_bytes) -> bool: ...
\r
59 class NoneAlgorithm(SigningAlgorithm):
\r
60 def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ...
\r
62 class HMACAlgorithm(SigningAlgorithm):
\r
63 default_digest_method = ... # type: Callable
\r
64 digest_method = ... # type: Callable
\r
65 def __init__(self, digest_method: Optional[Callable] = ...) -> None: ...
\r
66 def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ...
\r
69 default_digest_method = ... # type: Callable
\r
70 default_key_derivation = ... # type: str
\r
71 secret_key = ... # type: _can_become_bytes
\r
72 sep = ... # type: _can_become_bytes
\r
73 salt = ... # type: _can_become_bytes
\r
74 key_derivation = ... # type: str
\r
75 digest_method = ... # type: Callable
\r
76 algorithm = ... # type: SigningAlgorithm
\r
77 def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., sep: Optional[_can_become_bytes] = ...,
\r
78 key_derivation: Optional[str] = ...,
\r
79 digest_method: Optional[Callable] = ...,
\r
80 algorithm: Optional[SigningAlgorithm] = ...) -> None: ...
\r
81 def derive_key(self) -> bytes: ...
\r
82 def get_signature(self, value: _bytes_like) -> bytes: ...
\r
83 def sign(self, value: _bytes_like) -> bytes: ...
\r
84 def verify_signature(self, value: _bytes_like, sig: _can_become_bytes) -> bool: ...
\r
85 def unsign(self, signed_value: _bytes_like) -> bytes: ...
\r
86 def validate(self, signed_value: _can_become_bytes) -> bool: ...
\r
88 class TimestampSigner(Signer):
\r
89 def get_timestamp(self) -> int: ...
\r
90 def timestamp_to_datetime(self, ts: int) -> datetime: ...
\r
91 def sign(self, value: _bytes_like) -> bytes: ...
\r
92 def unsign(self, value: _can_become_bytes, max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ...
\r
93 def validate(self, signed_value: _can_become_bytes, max_age: Optional[int] = ...) -> bool: ...
\r
96 default_serializer = ... # type: _serializer
\r
97 default_signer = ... # type: Callable[..., Signer]
\r
98 secret_key = ... # type: Any
\r
99 salt = ... # type: _can_become_bytes
\r
100 serializer = ... # type: _serializer
\r
101 is_text_serializer = ... # type: bool
\r
102 signer = ... # type: Signer
\r
103 signer_kwargs = ... # type: MutableMapping
\r
104 def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ...
\r
105 def load_payload(self, payload: Any, serializer: Optional[_serializer] = ...) -> Any: ...
\r
106 def dump_payload(self, *args, **kwargs) -> bytes: ...
\r
107 def make_signer(self, salt: Optional[_can_become_bytes] = ...) -> Signer: ...
\r
108 def dumps(self, obj: Any, salt: Optional[_can_become_bytes] = ...) -> _str_like: ...
\r
109 def dump(self, obj: Any, f: IO, salt: Optional[_can_become_bytes] = ...) -> None: ...
\r
110 def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ...) -> Any: ...
\r
111 def load(self, f: IO, salt: Optional[_can_become_bytes] = ...): ...
\r
112 def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ...) -> Tuple[bool, Any]: ...
\r
113 def load_unsafe(self, f: IO, *args, **kwargs) -> Tuple[bool, Any]: ...
\r
115 class TimedSerializer(Serializer):
\r
116 default_signer = ... # type: Callable[..., TimestampSigner]
\r
117 def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ...
\r
118 def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., max_age: Optional[int] = ...) -> Tuple[bool, Any]: ...
\r
120 class JSONWebSignatureSerializer(Serializer):
\r
121 jws_algorithms = ... # type: MutableMapping[str, SigningAlgorithm]
\r
122 default_algorithm = ... # type: str
\r
123 default_serializer = ... # type: Any
\r
124 algorithm_name = ... # type: str
\r
125 algorithm = ... # type: Any
\r
126 def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ...
\r
127 def load_payload(self, payload: Any, serializer: Optional[_serializer] = ..., return_header: bool = ...) -> Any: ...
\r
128 def dump_payload(self, *args, **kwargs) -> bytes: ...
\r
129 def make_algorithm(self, algorithm_name: str) -> SigningAlgorithm: ...
\r
130 def make_signer(self, salt: Optional[_can_become_bytes] = ..., algorithm_name: Optional[str] = ...) -> Signer: ...
\r
131 def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ...
\r
132 def dumps(self, obj: Any, salt: Optional[_can_become_bytes] = ..., header_fields: Optional[MutableMapping]=...) -> str: ...
\r
133 def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Any: ...
\r
134 def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Tuple[bool, Any]: ...
\r
136 class TimedJSONWebSignatureSerializer(JSONWebSignatureSerializer):
\r
137 DEFAULT_EXPIRES_IN = ... # type: int
\r
138 expires_in = ... # type: int
\r
139 def __init__(self, secret_key: _can_become_bytes, expires_in: Optional[int] = ..., **kwargs) -> None: ...
\r
140 def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ...
\r
141 def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Any: ...
\r
142 def get_issue_date(self, header: MutableMapping) -> Optional[datetime]: ...
\r
143 def now(self) -> int: ...
\r
145 class URLSafeSerializerMixin:
\r
146 def load_payload(self, payload: Any, serializer: Any = ..., **kwargs) -> Any: ...
\r
147 def dump_payload(self, *args, **kwargs) -> bytes: ...
\r
149 class URLSafeSerializer(URLSafeSerializerMixin, Serializer):
\r
150 default_serializer = ... # type: Any
\r
152 class URLSafeTimedSerializer(URLSafeSerializerMixin, TimedSerializer):
\r
153 default_serializer = ... # type: Any
\r