Debian Codegraph @

src/python/backports/zstd/zipfile/__init__.pyi

raw symbols SCIP
1 import io
2 from _typeshed import SizedBuffer, StrOrBytesPath, StrPath
3 from collections.abc import Callable, Iterable, Iterator
4 from io import TextIOWrapper
5 from os import PathLike
6 from types import TracebackType
7 from typing import IO, Final, Literal, Protocol, TypeAlias, overload, type_check_only
8 from typing_extensions import Self
9
10 __all__ = [
11 "BadZipFile",
12 "BadZipfile",
13 "Path",
14 "error",
15 "ZIP_STORED",
16 "ZIP_DEFLATED",
17 "ZIP_BZIP2",
18 "ZIP_LZMA",
19 "is_zipfile",
20 "ZipInfo",
21 "ZipFile",
22 "PyZipFile",
23 "LargeZipFile",
24 "ZIP_ZSTANDARD",
25 ]
26
27 # TODO: use TypeAlias for these two when mypy bugs are fixed
28 # https://github.com/python/mypy/issues/16581
29 _DateTuple = tuple[int, int, int, int, int, int] # noqa: Y026
30 _ZipFileMode = Literal["r", "w", "x", "a"] # noqa: Y026
31
32 _ReadWriteMode: TypeAlias = Literal["r", "w"]
33
34 class BadZipFile(Exception): ...
35
36 BadZipfile = BadZipFile
37 error = BadZipfile
38
39 class LargeZipFile(Exception): ...
40
41 @type_check_only
42 class _ZipStream(Protocol):
43 def read(self, n: int, /) -> bytes: ...
44 # The following methods are optional:
45 # def seekable(self) -> bool: ...
46 # def tell(self) -> int: ...
47 # def seek(self, n: int, /) -> object: ...
48
49 # Stream shape as required by _EndRecData() and _EndRecData64().
50 @type_check_only
51 class _SupportsReadSeekTell(Protocol):
52 def read(self, n: int = ..., /) -> bytes: ...
53 def seek(self, cookie: int, whence: int, /) -> object: ...
54 def tell(self) -> int: ...
55
56 @type_check_only
57 class _ClosableZipStream(_ZipStream, Protocol):
58 def close(self) -> object: ...
59
60 class ZipExtFile(io.BufferedIOBase):
61 MAX_N: int
62 MIN_READ_SIZE: int
63 MAX_SEEK_READ: int
64 newlines: list[bytes] | None
65 mode: _ReadWriteMode
66 name: str
67
68 @overload
69 def __init__(
70 self, fileobj: _ClosableZipStream, mode: _ReadWriteMode, zipinfo: ZipInfo, pwd: bytes | None, close_fileobj: Literal[True]
71 ) -> None: ...
72 @overload
73 def __init__(
74 self,
75 fileobj: _ClosableZipStream,
76 mode: _ReadWriteMode,
77 zipinfo: ZipInfo,
78 pwd: bytes | None = None,
79 *,
80 close_fileobj: Literal[True],
81 ) -> None: ...
82 @overload
83 def __init__(
84 self,
85 fileobj: _ZipStream,
86 mode: _ReadWriteMode,
87 zipinfo: ZipInfo,
88 pwd: bytes | None = None,
89 close_fileobj: Literal[False] = False,
90 ) -> None: ...
91
92 def read(self, n: int | None = -1) -> bytes: ...
93 def readline(self, limit: int = -1) -> bytes: ... # type: ignore[override]
94 def peek(self, n: int = 1) -> bytes: ...
95 def read1(self, n: int | None) -> bytes: ... # type: ignore[override]
96 def seek(self, offset: int, whence: int = 0) -> int: ...
97
98 @type_check_only
99 class _Writer(Protocol):
100 def write(self, s: str, /) -> object: ...
101
102 @type_check_only
103 class _ZipReadable(Protocol):
104 def seek(self, offset: int, whence: int = 0, /) -> int: ...
105 def read(self, n: int = -1, /) -> bytes: ...
106
107 @type_check_only
108 class _ZipTellable(Protocol):
109 def tell(self) -> int: ...
110
111 @type_check_only
112 class _ZipReadableTellable(_ZipReadable, _ZipTellable, Protocol): ...
113
114 @type_check_only
115 class _ZipWritable(Protocol):
116 def flush(self) -> None: ...
117 def close(self) -> None: ...
118 def write(self, b: bytes, /) -> int: ...
119
120 class ZipFile:
121 filename: str | None
122 debug: int
123 comment: bytes
124 filelist: list[ZipInfo]
125 fp: IO[bytes] | None
126 NameToInfo: dict[str, ZipInfo]
127 start_dir: int # undocumented
128 compression: int # undocumented
129 compresslevel: int | None # undocumented
130 mode: _ZipFileMode # undocumented
131 pwd: bytes | None # undocumented
132 @overload
133 def __init__(
134 self,
135 file: StrPath | IO[bytes],
136 mode: _ZipFileMode = "r",
137 compression: int = 0,
138 allowZip64: bool = True,
139 compresslevel: int | None = None,
140 *,
141 strict_timestamps: bool = True,
142 metadata_encoding: str | None = None,
143 ) -> None: ...
144 # metadata_encoding is only allowed for read mode
145 @overload
146 def __init__(
147 self,
148 file: StrPath | _ZipReadable,
149 mode: Literal["r"] = "r",
150 compression: int = 0,
151 allowZip64: bool = True,
152 compresslevel: int | None = None,
153 *,
154 strict_timestamps: bool = True,
155 metadata_encoding: str | None = None,
156 ) -> None: ...
157 @overload
158 def __init__(
159 self,
160 file: StrPath | _ZipWritable,
161 mode: Literal["w", "x"],
162 compression: int = 0,
163 allowZip64: bool = True,
164 compresslevel: int | None = None,
165 *,
166 strict_timestamps: bool = True,
167 metadata_encoding: None = None,
168 ) -> None: ...
169 @overload
170 def __init__(
171 self,
172 file: StrPath | _ZipReadableTellable,
173 mode: Literal["a"],
174 compression: int = 0,
175 allowZip64: bool = True,
176 compresslevel: int | None = None,
177 *,
178 strict_timestamps: bool = True,
179 metadata_encoding: None = None,
180 ) -> None: ...
181
182 def __enter__(self) -> Self: ...
183 def __exit__(
184 self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
185 ) -> None: ...
186 def close(self) -> None: ...
187 def getinfo(self, name: str) -> ZipInfo: ...
188 def infolist(self) -> list[ZipInfo]: ...
189 def namelist(self) -> list[str]: ...
190 def open(
191 self, name: str | ZipInfo, mode: _ReadWriteMode = "r", pwd: bytes | None = None, *, force_zip64: bool = False
192 ) -> IO[bytes]: ...
193 def extract(self, member: str | ZipInfo, path: StrPath | None = None, pwd: bytes | None = None) -> str: ...
194 def extractall(
195 self, path: StrPath | None = None, members: Iterable[str | ZipInfo] | None = None, pwd: bytes | None = None
196 ) -> None: ...
197 def printdir(self, file: _Writer | None = None) -> None: ...
198 def setpassword(self, pwd: bytes) -> None: ...
199 def read(self, name: str | ZipInfo, pwd: bytes | None = None) -> bytes: ...
200 def testzip(self) -> str | None: ...
201 def write(
202 self,
203 filename: StrPath,
204 arcname: StrPath | None = None,
205 compress_type: int | None = None,
206 compresslevel: int | None = None,
207 ) -> None: ...
208 def writestr(
209 self,
210 zinfo_or_arcname: str | ZipInfo,
211 data: SizedBuffer | str,
212 compress_type: int | None = None,
213 compresslevel: int | None = None,
214 ) -> None: ...
215 def mkdir(self, zinfo_or_directory_name: str | ZipInfo, mode: int = 0o777) -> None: ...
216
217 def __del__(self) -> None: ...
218
219 class PyZipFile(ZipFile):
220 def __init__(
221 self, file: str | IO[bytes], mode: _ZipFileMode = "r", compression: int = 0, allowZip64: bool = True, optimize: int = -1
222 ) -> None: ...
223 def writepy(self, pathname: str, basename: str = "", filterfunc: Callable[[str], bool] | None = None) -> None: ...
224
225 class ZipInfo:
226 __slots__ = (
227 "orig_filename",
228 "filename",
229 "date_time",
230 "compress_type",
231 "compress_level",
232 "comment",
233 "extra",
234 "create_system",
235 "create_version",
236 "extract_version",
237 "reserved",
238 "flag_bits",
239 "volume",
240 "internal_attr",
241 "external_attr",
242 "header_offset",
243 "CRC",
244 "compress_size",
245 "file_size",
246 "_raw_time",
247 "_end_offset",
248 )
249 filename: str
250 date_time: _DateTuple
251 compress_type: int
252 comment: bytes
253 extra: bytes
254 create_system: int
255 create_version: int
256 extract_version: int
257 reserved: int
258 flag_bits: int
259 volume: int
260 internal_attr: int
261 external_attr: int
262 header_offset: int
263 CRC: int
264 compress_size: int
265 file_size: int
266 orig_filename: str # undocumented
267 compress_level: int | None
268
269 def __init__(self, filename: str = "NoName", date_time: _DateTuple = (1980, 1, 1, 0, 0, 0)) -> None: ...
270 @classmethod
271 def from_file(cls, filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True) -> Self: ...
272 def is_dir(self) -> bool: ...
273 def FileHeader(self, zip64: bool | None = None) -> bytes: ...
274 def _for_archive(self, archive: ZipFile) -> Self: ...
275
276 from zipfile._path import CompleteDirs as CompleteDirs, Path as Path
277
278 def is_zipfile(filename: StrOrBytesPath | _SupportsReadSeekTell) -> bool: ...
279
280 ZIP64_LIMIT: Final[int]
281 ZIP_FILECOUNT_LIMIT: Final[int]
282 ZIP_MAX_COMMENT: Final[int]
283
284 ZIP_STORED: Final = 0
285 ZIP_DEFLATED: Final = 8
286 ZIP_BZIP2: Final = 12
287 ZIP_LZMA: Final = 14
288 ZIP_ZSTANDARD: Final = 93
289
290 DEFAULT_VERSION: Final[int]
291 ZIP64_VERSION: Final[int]
292 BZIP2_VERSION: Final[int]
293 LZMA_VERSION: Final[int]
294 ZSTANDARD_VERSION: Final[int]
295 MAX_EXTRACT_VERSION: Final[int]