3 from _typeshed import Self, StrPath
4 from os import PathLike
5 from types import TracebackType
6 from typing import IO, Any, Callable, Iterable, Iterator, Protocol, Sequence, Tuple, Type, overload
7 from typing_extensions import Literal
9 _DateTuple = Tuple[int, int, int, int, int, int]
10 _ReadWriteMode = Literal["r", "w"]
11 _ReadWriteBinaryMode = Literal["r", "w", "rb", "wb"]
12 _ZipFileMode = Literal["r", "w", "x", "a"]
14 class BadZipFile(Exception): ...
16 BadZipfile = BadZipFile
19 class LargeZipFile(Exception): ...
21 class _ZipStream(Protocol):
22 def read(self, __n: int) -> bytes: ...
23 # The following methods are optional:
24 # def seekable(self) -> bool: ...
25 # def tell(self) -> int: ...
26 # def seek(self, __n: int) -> object: ...
28 class _ClosableZipStream(_ZipStream, Protocol):
29 def close(self) -> object: ...
31 class ZipExtFile(io.BufferedIOBase):
35 if sys.version_info >= (3, 7):
38 newlines: list[bytes] | None
41 if sys.version_info >= (3, 7):
45 fileobj: _ClosableZipStream,
49 close_fileobj: Literal[True],
54 fileobj: _ClosableZipStream,
57 pwd: bytes | None = ...,
59 close_fileobj: Literal[True],
67 pwd: bytes | None = ...,
68 close_fileobj: Literal[False] = ...,
74 fileobj: _ClosableZipStream,
77 decrypter: Callable[[Sequence[int]], bytes] | None,
78 close_fileobj: Literal[True],
83 fileobj: _ClosableZipStream,
86 decrypter: Callable[[Sequence[int]], bytes] | None = ...,
88 close_fileobj: Literal[True],
96 decrypter: Callable[[Sequence[int]], bytes] | None = ...,
97 close_fileobj: Literal[False] = ...,
99 def read(self, n: int | None = ...) -> bytes: ...
100 def readline(self, limit: int = ...) -> bytes: ... # type: ignore
101 def __repr__(self) -> str: ...
102 def peek(self, n: int = ...) -> bytes: ...
103 def read1(self, n: int | None) -> bytes: ... # type: ignore
104 if sys.version_info >= (3, 7):
105 def seek(self, offset: int, whence: int = ...) -> int: ...
107 class _Writer(Protocol):
108 def write(self, __s: str) -> object: ...
114 filelist: list[ZipInfo]
116 NameToInfo: dict[str, ZipInfo]
117 start_dir: int # undocumented
118 compression: int # undocumented
119 compresslevel: int | None # undocumented
120 mode: _ZipFileMode # undocumented
121 pwd: str | None # undocumented
122 if sys.version_info >= (3, 8):
125 file: StrPath | IO[bytes],
126 mode: _ZipFileMode = ...,
127 compression: int = ...,
128 allowZip64: bool = ...,
129 compresslevel: int | None = ...,
131 strict_timestamps: bool = ...,
133 elif sys.version_info >= (3, 7):
136 file: StrPath | IO[bytes],
137 mode: _ZipFileMode = ...,
138 compression: int = ...,
139 allowZip64: bool = ...,
140 compresslevel: int | None = ...,
144 self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ...
146 def __enter__(self: Self) -> Self: ...
148 self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
150 def close(self) -> None: ...
151 def getinfo(self, name: str) -> ZipInfo: ...
152 def infolist(self) -> list[ZipInfo]: ...
153 def namelist(self) -> list[str]: ...
155 self, name: str | ZipInfo, mode: _ReadWriteMode = ..., pwd: bytes | None = ..., *, force_zip64: bool = ...
157 def extract(self, member: str | ZipInfo, path: StrPath | None = ..., pwd: bytes | None = ...) -> str: ...
159 self, path: StrPath | None = ..., members: Iterable[str | ZipInfo] | None = ..., pwd: bytes | None = ...
161 def printdir(self, file: _Writer | None = ...) -> None: ...
162 def setpassword(self, pwd: bytes) -> None: ...
163 def read(self, name: str | ZipInfo, pwd: bytes | None = ...) -> bytes: ...
164 def testzip(self) -> str | None: ...
165 if sys.version_info >= (3, 7):
169 arcname: StrPath | None = ...,
170 compress_type: int | None = ...,
171 compresslevel: int | None = ...,
174 def write(self, filename: StrPath, arcname: StrPath | None = ..., compress_type: int | None = ...) -> None: ...
175 if sys.version_info >= (3, 7):
178 zinfo_or_arcname: str | ZipInfo,
180 compress_type: int | None = ...,
181 compresslevel: int | None = ...,
184 def writestr(self, zinfo_or_arcname: str | ZipInfo, data: bytes | str, compress_type: int | None = ...) -> None: ...
186 class PyZipFile(ZipFile):
188 self, file: str | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ..., optimize: int = ...
190 def writepy(self, pathname: str, basename: str = ..., filterfunc: Callable[[str], bool] | None = ...) -> None: ...
194 date_time: _DateTuple
210 orig_filename: str # undocumented
211 def __init__(self, filename: str = ..., date_time: _DateTuple = ...) -> None: ...
212 if sys.version_info >= (3, 8):
214 def from_file(cls, filename: StrPath, arcname: StrPath | None = ..., *, strict_timestamps: bool = ...) -> ZipInfo: ...
217 def from_file(cls, filename: StrPath, arcname: StrPath | None = ...) -> ZipInfo: ...
218 def is_dir(self) -> bool: ...
219 def FileHeader(self, zip64: bool | None = ...) -> bytes: ...
221 class _PathOpenProtocol(Protocol):
222 def __call__(self, mode: _ReadWriteMode = ..., pwd: bytes | None = ..., *, force_zip64: bool = ...) -> IO[bytes]: ...
224 if sys.version_info >= (3, 8):
227 def name(self) -> str: ...
229 def parent(self) -> PathLike[str]: ... # undocumented
230 if sys.version_info >= (3, 10):
232 def filename(self) -> PathLike[str]: ... # undocumented
233 def __init__(self, root: ZipFile | StrPath | IO[bytes], at: str = ...) -> None: ...
234 if sys.version_info >= (3, 9):
235 def open(self, mode: _ReadWriteBinaryMode = ..., *args: Any, pwd: bytes | None = ..., **kwargs: Any) -> IO[bytes]: ...
238 def open(self) -> _PathOpenProtocol: ...
239 def iterdir(self) -> Iterator[Path]: ...
240 def is_dir(self) -> bool: ...
241 def is_file(self) -> bool: ...
242 def exists(self) -> bool: ...
245 encoding: str | None = ...,
246 errors: str | None = ...,
247 newline: str | None = ...,
248 line_buffering: bool = ...,
249 write_through: bool = ...,
251 def read_bytes(self) -> bytes: ...
252 if sys.version_info >= (3, 10):
253 def joinpath(self, *other: StrPath) -> Path: ...
255 def joinpath(self, add: StrPath) -> Path: ... # undocumented
256 def __truediv__(self, add: StrPath) -> Path: ...
258 def is_zipfile(filename: StrPath | IO[bytes]) -> bool: ...
263 ZIP_FILECOUNT_LIMIT: int