massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / zipfile.pyi
1 import io
2 import sys
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
8
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"]
13
14 class BadZipFile(Exception): ...
15
16 BadZipfile = BadZipFile
17 error = BadZipfile
18
19 class LargeZipFile(Exception): ...
20
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: ...
27
28 class _ClosableZipStream(_ZipStream, Protocol):
29     def close(self) -> object: ...
30
31 class ZipExtFile(io.BufferedIOBase):
32     MAX_N: int
33     MIN_READ_SIZE: int
34
35     if sys.version_info >= (3, 7):
36         MAX_SEEK_READ: int
37
38     newlines: list[bytes] | None
39     mode: _ReadWriteMode
40     name: str
41     if sys.version_info >= (3, 7):
42         @overload
43         def __init__(
44             self,
45             fileobj: _ClosableZipStream,
46             mode: _ReadWriteMode,
47             zipinfo: ZipInfo,
48             pwd: bytes | None,
49             close_fileobj: Literal[True],
50         ) -> None: ...
51         @overload
52         def __init__(
53             self,
54             fileobj: _ClosableZipStream,
55             mode: _ReadWriteMode,
56             zipinfo: ZipInfo,
57             pwd: bytes | None = ...,
58             *,
59             close_fileobj: Literal[True],
60         ) -> None: ...
61         @overload
62         def __init__(
63             self,
64             fileobj: _ZipStream,
65             mode: _ReadWriteMode,
66             zipinfo: ZipInfo,
67             pwd: bytes | None = ...,
68             close_fileobj: Literal[False] = ...,
69         ) -> None: ...
70     else:
71         @overload
72         def __init__(
73             self,
74             fileobj: _ClosableZipStream,
75             mode: _ReadWriteMode,
76             zipinfo: ZipInfo,
77             decrypter: Callable[[Sequence[int]], bytes] | None,
78             close_fileobj: Literal[True],
79         ) -> None: ...
80         @overload
81         def __init__(
82             self,
83             fileobj: _ClosableZipStream,
84             mode: _ReadWriteMode,
85             zipinfo: ZipInfo,
86             decrypter: Callable[[Sequence[int]], bytes] | None = ...,
87             *,
88             close_fileobj: Literal[True],
89         ) -> None: ...
90         @overload
91         def __init__(
92             self,
93             fileobj: _ZipStream,
94             mode: _ReadWriteMode,
95             zipinfo: ZipInfo,
96             decrypter: Callable[[Sequence[int]], bytes] | None = ...,
97             close_fileobj: Literal[False] = ...,
98         ) -> None: ...
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: ...
106
107 class _Writer(Protocol):
108     def write(self, __s: str) -> object: ...
109
110 class ZipFile:
111     filename: str | None
112     debug: int
113     comment: bytes
114     filelist: list[ZipInfo]
115     fp: IO[bytes] | None
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):
123         def __init__(
124             self,
125             file: StrPath | IO[bytes],
126             mode: _ZipFileMode = ...,
127             compression: int = ...,
128             allowZip64: bool = ...,
129             compresslevel: int | None = ...,
130             *,
131             strict_timestamps: bool = ...,
132         ) -> None: ...
133     elif sys.version_info >= (3, 7):
134         def __init__(
135             self,
136             file: StrPath | IO[bytes],
137             mode: _ZipFileMode = ...,
138             compression: int = ...,
139             allowZip64: bool = ...,
140             compresslevel: int | None = ...,
141         ) -> None: ...
142     else:
143         def __init__(
144             self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ...
145         ) -> None: ...
146     def __enter__(self: Self) -> Self: ...
147     def __exit__(
148         self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
149     ) -> 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]: ...
154     def open(
155         self, name: str | ZipInfo, mode: _ReadWriteMode = ..., pwd: bytes | None = ..., *, force_zip64: bool = ...
156     ) -> IO[bytes]: ...
157     def extract(self, member: str | ZipInfo, path: StrPath | None = ..., pwd: bytes | None = ...) -> str: ...
158     def extractall(
159         self, path: StrPath | None = ..., members: Iterable[str | ZipInfo] | None = ..., pwd: bytes | None = ...
160     ) -> 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):
166         def write(
167             self,
168             filename: StrPath,
169             arcname: StrPath | None = ...,
170             compress_type: int | None = ...,
171             compresslevel: int | None = ...,
172         ) -> None: ...
173     else:
174         def write(self, filename: StrPath, arcname: StrPath | None = ..., compress_type: int | None = ...) -> None: ...
175     if sys.version_info >= (3, 7):
176         def writestr(
177             self,
178             zinfo_or_arcname: str | ZipInfo,
179             data: bytes | str,
180             compress_type: int | None = ...,
181             compresslevel: int | None = ...,
182         ) -> None: ...
183     else:
184         def writestr(self, zinfo_or_arcname: str | ZipInfo, data: bytes | str, compress_type: int | None = ...) -> None: ...
185
186 class PyZipFile(ZipFile):
187     def __init__(
188         self, file: str | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ..., optimize: int = ...
189     ) -> None: ...
190     def writepy(self, pathname: str, basename: str = ..., filterfunc: Callable[[str], bool] | None = ...) -> None: ...
191
192 class ZipInfo:
193     filename: str
194     date_time: _DateTuple
195     compress_type: int
196     comment: bytes
197     extra: bytes
198     create_system: int
199     create_version: int
200     extract_version: int
201     reserved: int
202     flag_bits: int
203     volume: int
204     internal_attr: int
205     external_attr: int
206     header_offset: int
207     CRC: int
208     compress_size: int
209     file_size: int
210     orig_filename: str  # undocumented
211     def __init__(self, filename: str = ..., date_time: _DateTuple = ...) -> None: ...
212     if sys.version_info >= (3, 8):
213         @classmethod
214         def from_file(cls, filename: StrPath, arcname: StrPath | None = ..., *, strict_timestamps: bool = ...) -> ZipInfo: ...
215     else:
216         @classmethod
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: ...
220
221 class _PathOpenProtocol(Protocol):
222     def __call__(self, mode: _ReadWriteMode = ..., pwd: bytes | None = ..., *, force_zip64: bool = ...) -> IO[bytes]: ...
223
224 if sys.version_info >= (3, 8):
225     class Path:
226         @property
227         def name(self) -> str: ...
228         @property
229         def parent(self) -> PathLike[str]: ...  # undocumented
230         if sys.version_info >= (3, 10):
231             @property
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]: ...
236         else:
237             @property
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: ...
243         def read_text(
244             self,
245             encoding: str | None = ...,
246             errors: str | None = ...,
247             newline: str | None = ...,
248             line_buffering: bool = ...,
249             write_through: bool = ...,
250         ) -> str: ...
251         def read_bytes(self) -> bytes: ...
252         if sys.version_info >= (3, 10):
253             def joinpath(self, *other: StrPath) -> Path: ...
254         else:
255             def joinpath(self, add: StrPath) -> Path: ...  # undocumented
256         def __truediv__(self, add: StrPath) -> Path: ...
257
258 def is_zipfile(filename: StrPath | IO[bytes]) -> bool: ...
259
260 ZIP_STORED: int
261 ZIP_DEFLATED: int
262 ZIP64_LIMIT: int
263 ZIP_FILECOUNT_LIMIT: int
264 ZIP_MAX_COMMENT: int
265 ZIP_BZIP2: int
266 ZIP_LZMA: int