-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy path__init__.pyi
More file actions
417 lines (384 loc) · 12.7 KB
/
__init__.pyi
File metadata and controls
417 lines (384 loc) · 12.7 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import io
import sys
from _typeshed import SizedBuffer, StrOrBytesPath, StrPath
from collections.abc import Callable, Iterable, Iterator
from io import TextIOWrapper
from os import PathLike
from types import TracebackType
from typing import IO, Final, Literal, Protocol, overload, type_check_only
from typing_extensions import Self, TypeAlias
__all__ = [
"BadZipFile",
"BadZipfile",
"Path",
"error",
"ZIP_STORED",
"ZIP_DEFLATED",
"ZIP_BZIP2",
"ZIP_LZMA",
"is_zipfile",
"ZipInfo",
"ZipFile",
"PyZipFile",
"LargeZipFile",
]
if sys.version_info >= (3, 14):
__all__ += ["ZIP_ZSTANDARD"]
# TODO: use TypeAlias for these two when mypy bugs are fixed
# https://github.com/python/mypy/issues/16581
_DateTuple = tuple[int, int, int, int, int, int] # noqa: Y026
_ZipFileMode = Literal["r", "w", "x", "a"] # noqa: Y026
_ReadWriteMode: TypeAlias = Literal["r", "w"]
class BadZipFile(Exception): ...
BadZipfile = BadZipFile
error = BadZipfile
class LargeZipFile(Exception): ...
@type_check_only
class _ZipStream(Protocol):
def read(self, n: int, /) -> bytes: ...
# The following methods are optional:
# def seekable(self) -> bool: ...
# def tell(self) -> int: ...
# def seek(self, n: int, /) -> object: ...
# Stream shape as required by _EndRecData() and _EndRecData64().
@type_check_only
class _SupportsReadSeekTell(Protocol):
def read(self, n: int = ..., /) -> bytes: ...
def seek(self, cookie: int, whence: int, /) -> object: ...
def tell(self) -> int: ...
@type_check_only
class _ClosableZipStream(_ZipStream, Protocol):
def close(self) -> object: ...
class ZipExtFile(io.BufferedIOBase):
MAX_N: int
MIN_READ_SIZE: int
MAX_SEEK_READ: int
newlines: list[bytes] | None
mode: _ReadWriteMode
name: str
@overload
def __init__(
self, fileobj: _ClosableZipStream, mode: _ReadWriteMode, zipinfo: ZipInfo, pwd: bytes | None, close_fileobj: Literal[True]
) -> None: ...
@overload
def __init__(
self,
fileobj: _ClosableZipStream,
mode: _ReadWriteMode,
zipinfo: ZipInfo,
pwd: bytes | None = None,
*,
close_fileobj: Literal[True],
) -> None: ...
@overload
def __init__(
self,
fileobj: _ZipStream,
mode: _ReadWriteMode,
zipinfo: ZipInfo,
pwd: bytes | None = None,
close_fileobj: Literal[False] = False,
) -> None: ...
def read(self, n: int | None = -1) -> bytes: ...
def readline(self, limit: int = -1) -> bytes: ... # type: ignore[override]
def peek(self, n: int = 1) -> bytes: ...
def read1(self, n: int | None) -> bytes: ... # type: ignore[override]
def seek(self, offset: int, whence: int = 0) -> int: ...
@type_check_only
class _Writer(Protocol):
def write(self, s: str, /) -> object: ...
@type_check_only
class _ZipReadable(Protocol):
def seek(self, offset: int, whence: int = 0, /) -> int: ...
def read(self, n: int = -1, /) -> bytes: ...
@type_check_only
class _ZipTellable(Protocol):
def tell(self) -> int: ...
@type_check_only
class _ZipReadableTellable(_ZipReadable, _ZipTellable, Protocol): ...
@type_check_only
class _ZipWritable(Protocol):
def flush(self) -> None: ...
def close(self) -> None: ...
def write(self, b: bytes, /) -> int: ...
class ZipFile:
filename: str | None
debug: int
comment: bytes
filelist: list[ZipInfo]
fp: IO[bytes] | None
NameToInfo: dict[str, ZipInfo]
start_dir: int # undocumented
compression: int # undocumented
compresslevel: int | None # undocumented
mode: _ZipFileMode # undocumented
pwd: bytes | None # undocumented
# metadata_encoding is new in 3.11
if sys.version_info >= (3, 11):
@overload
def __init__(
self,
file: StrPath | IO[bytes],
mode: _ZipFileMode = "r",
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
metadata_encoding: str | None = None,
) -> None: ...
# metadata_encoding is only allowed for read mode
@overload
def __init__(
self,
file: StrPath | _ZipReadable,
mode: Literal["r"] = "r",
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
metadata_encoding: str | None = None,
) -> None: ...
@overload
def __init__(
self,
file: StrPath | _ZipWritable,
mode: Literal["w", "x"],
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
metadata_encoding: None = None,
) -> None: ...
@overload
def __init__(
self,
file: StrPath | _ZipReadableTellable,
mode: Literal["a"],
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
metadata_encoding: None = None,
) -> None: ...
else:
@overload
def __init__(
self,
file: StrPath | IO[bytes],
mode: _ZipFileMode = "r",
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
) -> None: ...
@overload
def __init__(
self,
file: StrPath | _ZipReadable,
mode: Literal["r"] = "r",
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
) -> None: ...
@overload
def __init__(
self,
file: StrPath | _ZipWritable,
mode: Literal["w", "x"],
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
) -> None: ...
@overload
def __init__(
self,
file: StrPath | _ZipReadableTellable,
mode: Literal["a"],
compression: int = 0,
allowZip64: bool = True,
compresslevel: int | None = None,
*,
strict_timestamps: bool = True,
) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...
def close(self) -> None: ...
def getinfo(self, name: str) -> ZipInfo: ...
def infolist(self) -> list[ZipInfo]: ...
def namelist(self) -> list[str]: ...
def open(
self, name: str | ZipInfo, mode: _ReadWriteMode = "r", pwd: bytes | None = None, *, force_zip64: bool = False
) -> IO[bytes]: ...
def extract(self, member: str | ZipInfo, path: StrPath | None = None, pwd: bytes | None = None) -> str: ...
def extractall(
self, path: StrPath | None = None, members: Iterable[str | ZipInfo] | None = None, pwd: bytes | None = None
) -> None: ...
def printdir(self, file: _Writer | None = None) -> None: ...
def setpassword(self, pwd: bytes) -> None: ...
def read(self, name: str | ZipInfo, pwd: bytes | None = None) -> bytes: ...
def testzip(self) -> str | None: ...
def write(
self,
filename: StrPath,
arcname: StrPath | None = None,
compress_type: int | None = None,
compresslevel: int | None = None,
) -> None: ...
def writestr(
self,
zinfo_or_arcname: str | ZipInfo,
data: SizedBuffer | str,
compress_type: int | None = None,
compresslevel: int | None = None,
) -> None: ...
if sys.version_info >= (3, 11):
def mkdir(self, zinfo_or_directory_name: str | ZipInfo, mode: int = 0o777) -> None: ...
def __del__(self) -> None: ...
class PyZipFile(ZipFile):
def __init__(
self, file: str | IO[bytes], mode: _ZipFileMode = "r", compression: int = 0, allowZip64: bool = True, optimize: int = -1
) -> None: ...
def writepy(self, pathname: str, basename: str = "", filterfunc: Callable[[str], bool] | None = None) -> None: ...
class ZipInfo:
__slots__ = (
"orig_filename",
"filename",
"date_time",
"compress_type",
"compress_level",
"comment",
"extra",
"create_system",
"create_version",
"extract_version",
"reserved",
"flag_bits",
"volume",
"internal_attr",
"external_attr",
"header_offset",
"CRC",
"compress_size",
"file_size",
"_raw_time",
"_end_offset",
)
filename: str
date_time: _DateTuple
compress_type: int
comment: bytes
extra: bytes
create_system: int
create_version: int
extract_version: int
reserved: int
flag_bits: int
volume: int
internal_attr: int
external_attr: int
header_offset: int
CRC: int
compress_size: int
file_size: int
orig_filename: str # undocumented
if sys.version_info >= (3, 13):
compress_level: int | None
def __init__(self, filename: str = "NoName", date_time: _DateTuple = (1980, 1, 1, 0, 0, 0)) -> None: ...
@classmethod
def from_file(cls, filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True) -> Self: ...
def is_dir(self) -> bool: ...
def FileHeader(self, zip64: bool | None = None) -> bytes: ...
if sys.version_info >= (3, 14):
def _for_archive(self, archive: ZipFile) -> Self: ...
if sys.version_info >= (3, 12):
from zipfile._path import CompleteDirs as CompleteDirs, Path as Path
else:
class CompleteDirs(ZipFile):
def resolve_dir(self, name: str) -> str: ...
@overload
@classmethod
def make(cls, source: ZipFile) -> CompleteDirs: ...
@overload
@classmethod
def make(cls, source: StrPath | IO[bytes]) -> Self: ...
class Path:
root: CompleteDirs
at: str
def __init__(self, root: ZipFile | StrPath | IO[bytes], at: str = "") -> None: ...
@property
def name(self) -> str: ...
@property
def parent(self) -> PathLike[str]: ... # undocumented
if sys.version_info >= (3, 10):
@property
def filename(self) -> PathLike[str]: ... # undocumented
if sys.version_info >= (3, 11):
@property
def suffix(self) -> str: ...
@property
def suffixes(self) -> list[str]: ...
@property
def stem(self) -> str: ...
@overload
def open(
self,
mode: Literal["r", "w"] = "r",
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
line_buffering: bool = False,
write_through: bool = False,
*,
pwd: bytes | None = None,
) -> TextIOWrapper: ...
@overload
def open(self, mode: Literal["rb", "wb"], *, pwd: bytes | None = None) -> IO[bytes]: ...
if sys.version_info >= (3, 10):
def iterdir(self) -> Iterator[Self]: ...
else:
def iterdir(self) -> Iterator[Path]: ...
def is_dir(self) -> bool: ...
def is_file(self) -> bool: ...
def exists(self) -> bool: ...
def read_text(
self,
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
line_buffering: bool = False,
write_through: bool = False,
) -> str: ...
def read_bytes(self) -> bytes: ...
if sys.version_info >= (3, 10):
def joinpath(self, *other: StrPath) -> Path: ...
else:
def joinpath(self, add: StrPath) -> Path: ... # undocumented
def __truediv__(self, add: StrPath) -> Path: ...
def is_zipfile(filename: StrOrBytesPath | _SupportsReadSeekTell) -> bool: ...
ZIP64_LIMIT: Final[int]
ZIP_FILECOUNT_LIMIT: Final[int]
ZIP_MAX_COMMENT: Final[int]
ZIP_STORED: Final = 0
ZIP_DEFLATED: Final = 8
ZIP_BZIP2: Final = 12
ZIP_LZMA: Final = 14
if sys.version_info >= (3, 14):
ZIP_ZSTANDARD: Final = 93
DEFAULT_VERSION: Final[int]
ZIP64_VERSION: Final[int]
BZIP2_VERSION: Final[int]
LZMA_VERSION: Final[int]
if sys.version_info >= (3, 14):
ZSTANDARD_VERSION: Final[int]
MAX_EXTRACT_VERSION: Final[int]