1
-
# Better codecs stubs hand-written by o11c.
2
-
# https://docs.python.org/2/library/codecs.html and https://docs.python.org/3/library/codecs.html
3
1
import sys
4
-
from typing import (
5
-
Any,
6
-
BinaryIO,
7
-
Callable,
8
-
Generator,
9
-
IO,
10
-
Iterable,
11
-
List,
12
-
Optional,
13
-
Text,
14
-
TextIO,
15
-
Tuple,
16
-
Type,
17
-
TypeVar,
18
-
Union,
19
-
)
2
+
from typing import Any, BinaryIO, Callable, Generator, IO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union
20
3
21
4
from abc import abstractmethod
22
5
import types
23
6
24
-
25
7
# TODO: this only satisfies the most common interface, where
26
8
# bytes (py2 str) is the raw form and str (py2 unicode) is the cooked form.
27
9
# In the long run, both should become template parameters maybe?
28
10
# There *are* bytes->bytes and str->str encodings in the standard library.
29
11
# They are much more common in Python 2 than in Python 3.
30
-
# Python 3.5 supposedly might change something there.
31
12
32
-
_decoded = Text
33
-
_encoded = bytes
13
+
_Decoded = Text
14
+
_Encoded = bytes
34
15
35
16
# TODO: It is not possible to specify these signatures correctly, because
36
17
# they have an optional positional or keyword argument for errors=.
37
-
_encode_type = Callable[[_decoded], Tuple[_encoded, int]] # signature of Codec().encode
38
-
_decode_type = Callable[[_encoded], Tuple[_decoded, int]] # signature of Codec().decode
39
-
_stream_reader_type = Callable[[IO[_encoded]], 'StreamReader'] # signature of StreamReader __init__
40
-
_stream_writer_type = Callable[[IO[_encoded]], 'StreamWriter'] # signature of StreamWriter __init__
41
-
_incremental_encoder_type = Callable[[], 'IncrementalEncoder'] # signature of IncrementalEncoder __init__
42
-
_incremental_decoder_type = Callable[[], 'IncrementalDecoder'] # signature of IncrementalDecoder __init__
43
-
44
-
45
-
def encode(obj: _decoded, encoding: str = ..., errors: str = ...) -> _encoded:
46
-
...
47
-
def decode(obj: _encoded, encoding: str = ..., errors: str = ...) -> _decoded:
48
-
...
49
-
50
-
def lookup(encoding: str) -> 'CodecInfo':
51
-
...
52
-
class CodecInfo(Tuple[_encode_type, _decode_type, _stream_reader_type, _stream_writer_type]):
18
+
_Encoder = Callable[[_Decoded], Tuple[_Encoded, int]] # signature of Codec().encode
19
+
_Decoder = Callable[[_Encoded], Tuple[_Decoded, int]] # signature of Codec().decode
20
+
_StreamReader = Callable[[IO[_Encoded]], StreamReader] # signature of StreamReader __init__
21
+
_StreamWriter = Callable[[IO[_Encoded]], StreamWriter] # signature of StreamWriter __init__
22
+
_IncrementalEncoder = Callable[[], IncrementalEncoder] # signature of IncrementalEncoder __init__
23
+
_IncrementalDecoder = Callable[[], IncrementalDecoder] # signature of IncrementalDecoder __init__
24
+
def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ...
25
+
def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ...
26
+
def lookup(encoding: str) -> CodecInfo: ...
27
+
28
+
class CodecInfo(Tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
53
29
@property
54
-
def encode(self) -> _encode_type: ...
30
+
def encode(self) -> _Encoder: ...
55
31
@property
56
-
def decode(self) -> _decode_type: ...
32
+
def decode(self) -> _Decoder: ...
57
33
@property
58
-
def streamreader(self) -> _stream_reader_type: ...
34
+
def streamreader(self) -> _StreamReader: ...
59
35
@property
60
-
def streamwriter(self) -> _stream_writer_type: ...
36
+
def streamwriter(self) -> _StreamWriter: ...
61
37
@property
62
-
def incrementalencoder(self) -> _incremental_encoder_type: ...
38
+
def incrementalencoder(self) -> _IncrementalEncoder: ...
63
39
@property
64
-
def incrementaldecoder(self) -> _incremental_decoder_type: ...
40
+
def incrementaldecoder(self) -> _IncrementalDecoder: ...
65
41
name: str
66
-
def __init__(self, encode: _encode_type, decode: _decode_type, streamreader: _stream_reader_type = ..., streamwriter: _stream_writer_type = ..., incrementalencoder: _incremental_encoder_type = ..., incrementaldecoder: _incremental_decoder_type = ..., name: str = ...) -> None: ...
67
-
68
-
def getencoder(encoding: str) -> _encode_type:
69
-
...
70
-
def getdecoder(encoding: str) -> _decode_type:
71
-
...
72
-
def getincrementalencoder(encoding: str) -> _incremental_encoder_type:
73
-
...
74
-
def getincrementaldecoder(encoding: str) -> _incremental_decoder_type:
75
-
...
76
-
def getreader(encoding: str) -> _stream_reader_type:
77
-
...
78
-
def getwriter(encoding: str) -> _stream_writer_type:
79
-
...
80
-
81
-
def register(search_function: Callable[[str], CodecInfo]) -> None:
82
-
...
83
-
84
-
def open(filename: str, mode: str = ..., encoding: str = ..., errors: str = ..., buffering: int = ...) -> StreamReaderWriter:
85
-
...
86
-
87
-
def EncodedFile(file: IO[_encoded], data_encoding: str, file_encoding: str = ..., errors: str = ...) -> 'StreamRecoder':
88
-
...
89
-
90
-
def iterencode(iterator: Iterable[_decoded], encoding: str, errors: str = ...) -> Generator[_encoded, None, None]:
91
-
...
92
-
def iterdecode(iterator: Iterable[_encoded], encoding: str, errors: str = ...) -> Generator[_decoded, None, None]:
93
-
...
94
-
95
-
BOM = b''
96
-
BOM_BE = b''
97
-
BOM_LE = b''
98
-
BOM_UTF8 = b''
99
-
BOM_UTF16 = b''
100
-
BOM_UTF16_BE = b''
101
-
BOM_UTF16_LE = b''
102
-
BOM_UTF32 = b''
103
-
BOM_UTF32_BE = b''
104
-
BOM_UTF32_LE = b''
42
+
def __init__(
43
+
self,
44
+
encode: _Encoder,
45
+
decode: _Decoder,
46
+
streamreader: _StreamReader = ...,
47
+
streamwriter: _StreamWriter = ...,
48
+
incrementalencoder: _IncrementalEncoder = ...,
49
+
incrementaldecoder: _IncrementalDecoder = ...,
50
+
name: str = ...,
51
+
) -> None: ...
52
+
53
+
def getencoder(encoding: str) -> _Encoder: ...
54
+
def getdecoder(encoding: str) -> _Decoder: ...
55
+
def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ...
56
+
def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ...
57
+
def getreader(encoding: str) -> _StreamReader: ...
58
+
def getwriter(encoding: str) -> _StreamWriter: ...
59
+
def register(search_function: Callable[[str], CodecInfo]) -> None: ...
60
+
def open(filename: str, mode: str = ..., encoding: str = ..., errors: str = ..., buffering: int = ...) -> StreamReaderWriter: ...
61
+
def EncodedFile(file: IO[_Encoded], data_encoding: str, file_encoding: str = ..., errors: str = ...) -> StreamRecoder: ...
62
+
def iterencode(iterator: Iterable[_Decoded], encoding: str, errors: str = ...) -> Generator[_Encoded, None, None]: ...
63
+
def iterdecode(iterator: Iterable[_Encoded], encoding: str, errors: str = ...) -> Generator[_Decoded, None, None]: ...
64
+
65
+
BOM: bytes
66
+
BOM_BE: bytes
67
+
BOM_LE: bytes
68
+
BOM_UTF8: bytes
69
+
BOM_UTF16: bytes
70
+
BOM_UTF16_BE: bytes
71
+
BOM_UTF16_LE: bytes
72
+
BOM_UTF32: bytes
73
+
BOM_UTF32_BE: bytes
74
+
BOM_UTF32_LE: bytes
105
75
106
76
# It is expected that different actions be taken depending on which of the
107
77
# three subclasses of `UnicodeError` is actually ...ed. However, the Union
108
78
# is still needed for at least one of the cases.
109
-
def register_error(name: str, error_handler: Callable[[UnicodeError], Tuple[Union[str, bytes], int]]) -> None:
110
-
...
111
-
def lookup_error(name: str) -> Callable[[UnicodeError], Tuple[Union[str, bytes], int]]:
112
-
...
113
-
114
-
def strict_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]:
115
-
...
116
-
def replace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]:
117
-
...
118
-
def ignore_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]:
119
-
...
120
-
def xmlcharrefreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]:
121
-
...
122
-
def backslashreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]:
123
-
...
79
+
def register_error(name: str, error_handler: Callable[[UnicodeError], Tuple[Union[str, bytes], int]]) -> None: ...
80
+
def lookup_error(name: str) -> Callable[[UnicodeError], Tuple[Union[str, bytes], int]]: ...
81
+
def strict_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ...
82
+
def replace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ...
83
+
def ignore_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ...
84
+
def xmlcharrefreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ...
85
+
def backslashreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ...
124
86
125
87
class Codec:
126
88
# These are sort of @abstractmethod but sort of not.
127
89
# The StreamReader and StreamWriter subclasses only implement one.
128
-
def encode(self, input: _decoded, errors: str = ...) -> Tuple[_encoded, int]:
129
-
...
130
-
def decode(self, input: _encoded, errors: str = ...) -> Tuple[_decoded, int]:
131
-
...
90
+
def encode(self, input: _Decoded, errors: str = ...) -> Tuple[_Encoded, int]: ...
91
+
def decode(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ...
132
92
133
93
class IncrementalEncoder:
134
-
errors = ... # type: str
135
-
def __init__(self, errors: str = ...) -> None:
136
-
...
94
+
errors: str
95
+
def __init__(self, errors: str = ...) -> None: ...
137
96
@abstractmethod
138
-
def encode(self, object: _decoded, final: bool = ...) -> _encoded:
139
-
...
140
-
def reset(self) -> None:
141
-
...
97
+
def encode(self, object: _Decoded, final: bool = ...) -> _Encoded: ...
98
+
def reset(self) -> None: ...
142
99
# documentation says int but str is needed for the subclass.
143
-
def getstate(self) -> Union[int, _decoded]:
144
-
...
145
-
def setstate(self, state: Union[int, _decoded]) -> None:
146
-
...
100
+
def getstate(self) -> Union[int, _Decoded]: ...
101
+
def setstate(self, state: Union[int, _Decoded]) -> None: ...
147
102
148
103
class IncrementalDecoder:
149
-
errors = ... # type: str
150
-
def __init__(self, errors: str = ...) -> None:
151
-
...
104
+
errors: str
105
+
def __init__(self, errors: str = ...) -> None: ...
152
106
@abstractmethod
153
-
def decode(self, object: _encoded, final: bool = ...) -> _decoded:
154
-
...
155
-
def reset(self) -> None:
156
-
...
157
-
def getstate(self) -> Tuple[_encoded, int]:
158
-
...
159
-
def setstate(self, state: Tuple[_encoded, int]) -> None:
160
-
...
107
+
def decode(self, object: _Encoded, final: bool = ...) -> _Decoded: ...
108
+
def reset(self) -> None: ...
109
+
def getstate(self) -> Tuple[_Encoded, int]: ...
110
+
def setstate(self, state: Tuple[_Encoded, int]) -> None: ...
161
111
162
112
# These are not documented but used in encodings/*.py implementations.
163
113
class BufferedIncrementalEncoder(IncrementalEncoder):
164
-
buffer = ... # type: str
165
-
def __init__(self, errors: str = ...) -> None:
166
-
...
114
+
buffer: str
115
+
def __init__(self, errors: str = ...) -> None: ...
167
116
@abstractmethod
168
-
def _buffer_encode(self, input: _decoded, errors: str, final: bool) -> _encoded:
169
-
...
170
-
def encode(self, input: _decoded, final: bool = ...) -> _encoded:
171
-
...
117
+
def _buffer_encode(self, input: _Decoded, errors: str, final: bool) -> _Encoded: ...
118
+
def encode(self, input: _Decoded, final: bool = ...) -> _Encoded: ...
119
+
172
120
class BufferedIncrementalDecoder(IncrementalDecoder):
173
-
buffer = ... # type: bytes
174
-
def __init__(self, errors: str = ...) -> None:
175
-
...
121
+
buffer: bytes
122
+
def __init__(self, errors: str = ...) -> None: ...
176
123
@abstractmethod
177
-
def _buffer_decode(self, input: _encoded, errors: str, final: bool) -> Tuple[_decoded, int]:
178
-
...
179
-
def decode(self, object: _encoded, final: bool = ...) -> _decoded:
180
-
...
124
+
def _buffer_decode(self, input: _Encoded, errors: str, final: bool) -> Tuple[_Decoded, int]: ...
125
+
def decode(self, object: _Encoded, final: bool = ...) -> _Decoded: ...
181
126
182
127
# TODO: it is not possible to specify the requirement that all other
183
128
# attributes and methods are passed-through from the stream.
184
129
class StreamWriter(Codec):
185
-
errors = ... # type: str
186
-
def __init__(self, stream: IO[_encoded], errors: str = ...) -> None:
187
-
...
188
-
def write(self, obj: _decoded) -> None:
189
-
...
190
-
def writelines(self, list: Iterable[_decoded]) -> None:
191
-
...
192
-
def reset(self) -> None:
193
-
...
130
+
errors: str
131
+
def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ...
132
+
def write(self, obj: _Decoded) -> None: ...
133
+
def writelines(self, list: Iterable[_Decoded]) -> None: ...
134
+
def reset(self) -> None: ...
194
135
195
136
class StreamReader(Codec):
196
-
errors = ... # type: str
197
-
def __init__(self, stream: IO[_encoded], errors: str = ...) -> None:
198
-
...
199
-
def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> _decoded:
200
-
...
201
-
def readline(self, size: int = ..., keepends: bool = ...) -> _decoded:
202
-
...
203
-
def readlines(self, sizehint: int = ..., keepends: bool = ...) -> List[_decoded]:
204
-
...
205
-
def reset(self) -> None:
206
-
...
137
+
errors: str
138
+
def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ...
139
+
def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> _Decoded: ...
140
+
def readline(self, size: int = ..., keepends: bool = ...) -> _Decoded: ...
141
+
def readlines(self, sizehint: int = ..., keepends: bool = ...) -> List[_Decoded]: ...
142
+
def reset(self) -> None: ...
207
143
208
-
_T = TypeVar('_T', bound='StreamReaderWriter')
144
+
_T = TypeVar("_T", bound=StreamReaderWriter)
209
145
210
146
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
211
147
# and delegates attributes to the underlying binary stream with __getattr__.
212
148
class StreamReaderWriter(TextIO):
213
-
def __init__(self, stream: IO[_encoded], Reader: _stream_reader_type, Writer: _stream_writer_type, errors: str = ...) -> None: ...
214
-
def read(self, size: int= ...) -> _decoded: ...
215
-
def readline(self, size: Optional[int] = ...) -> _decoded: ...
216
-
def readlines(self, sizehint: Optional[int] = ...) -> List[_decoded]: ...
149
+
def __init__(self, stream: IO[_Encoded], Reader: _StreamReader, Writer: _StreamWriter, errors: str = ...) -> None: ...
150
+
def read(self, size: int = ...) -> _Decoded: ...
151
+
def readline(self, size: Optional[int] = ...) -> _Decoded: ...
152
+
def readlines(self, sizehint: Optional[int] = ...) -> List[_Decoded]: ...
217
153
if sys.version_info >= (3,):
218
154
def __next__(self) -> Text: ...
219
155
else:
220
156
def next(self) -> Text: ...
221
157
def __iter__(self: _T) -> _T: ...
222
158
# This actually returns None, but that's incompatible with the supertype
223
-
def write(self, data: _decoded) -> int: ...
224
-
def writelines(self, list: Iterable[_decoded]) -> None: ...
159
+
def write(self, data: _Decoded) -> int: ...
160
+
def writelines(self, list: Iterable[_Decoded]) -> None: ...
225
161
def reset(self) -> None: ...
226
162
# Same as write()
227
163
def seek(self, offset: int, whence: int = ...) -> int: ...
228
164
def __enter__(self: _T) -> _T: ...
229
-
def __exit__(self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]) -> bool: ...
165
+
def __exit__(
166
+
self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
167
+
) -> bool: ...
230
168
def __getattr__(self, name: str) -> Any: ...
231
-
232
169
# These methods don't actually exist directly, but they are needed to satisfy the TextIO
233
170
# interface. At runtime, they are delegated through __getattr__.
234
171
def close(self) -> None: ...
@@ -241,11 +178,18 @@ class StreamReaderWriter(TextIO):
241
178
def tell(self) -> int: ...
242
179
def writable(self) -> bool: ...
243
180
244
-
_SRT = TypeVar('_SRT', bound=StreamRecoder)
181
+
_SRT = TypeVar("_SRT", bound=StreamRecoder)
245
182
246
183
class StreamRecoder(BinaryIO):
247
-
def __init__(self, stream: IO[_encoded], encode: _encode_type, decode: _decode_type, Reader: _stream_reader_type, Writer: _stream_writer_type, errors: str = ...) -> None:
248
-
...
184
+
def __init__(
185
+
self,
186
+
stream: IO[_Encoded],
187
+
encode: _Encoder,
188
+
decode: _Decoder,
189
+
Reader: _StreamReader,
190
+
Writer: _StreamWriter,
191
+
errors: str = ...,
192
+
) -> None: ...
249
193
def read(self, size: int = ...) -> bytes: ...
250
194
def readline(self, size: Optional[int] = ...) -> bytes: ...
251
195
def readlines(self, sizehint: Optional[int] = ...) -> List[bytes]: ...
@@ -259,8 +203,9 @@ class StreamRecoder(BinaryIO):
259
203
def reset(self) -> None: ...
260
204
def __getattr__(self, name: str) -> Any: ...
261
205
def __enter__(self: _SRT) -> _SRT: ...
262
-
def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType]) -> bool: ...
263
-
206
+
def __exit__(
207
+
self, type: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType]
208
+
) -> bool: ...
264
209
# These methods don't actually exist directly, but they are needed to satisfy the BinaryIO
265
210
# interface. At runtime, they are delegated through __getattr__.
266
211
def seek(self, offset: int, whence: int = ...) -> int: ...
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4