massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / tarfile.pyi
1 import bz2
2 import io
3 import sys
4 from _typeshed import Self, StrOrBytesPath, StrPath
5 from collections.abc import Callable, Iterable, Iterator, Mapping
6 from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj
7 from types import TracebackType
8 from typing import IO, Protocol, Tuple, Type, TypeVar, overload
9 from typing_extensions import Literal
10
11 _TF = TypeVar("_TF", bound=TarFile)
12
13 class _Fileobj(Protocol):
14     def read(self, __size: int) -> bytes: ...
15     def write(self, __b: bytes) -> object: ...
16     def tell(self) -> int: ...
17     def seek(self, __pos: int) -> object: ...
18     def close(self) -> object: ...
19     # Optional fields:
20     # name: str | bytes
21     # mode: Literal["rb", "r+b", "wb", "xb"]
22
23 class _Bz2ReadableFileobj(bz2._ReadableFileobj):
24     def close(self) -> object: ...
25
26 class _Bz2WritableFileobj(bz2._WritableFileobj):
27     def close(self) -> object: ...
28
29 # tar constants
30 NUL: bytes
31 BLOCKSIZE: int
32 RECORDSIZE: int
33 GNU_MAGIC: bytes
34 POSIX_MAGIC: bytes
35
36 LENGTH_NAME: int
37 LENGTH_LINK: int
38 LENGTH_PREFIX: int
39
40 REGTYPE: bytes
41 AREGTYPE: bytes
42 LNKTYPE: bytes
43 SYMTYPE: bytes
44 CONTTYPE: bytes
45 BLKTYPE: bytes
46 DIRTYPE: bytes
47 FIFOTYPE: bytes
48 CHRTYPE: bytes
49
50 GNUTYPE_LONGNAME: bytes
51 GNUTYPE_LONGLINK: bytes
52 GNUTYPE_SPARSE: bytes
53
54 XHDTYPE: bytes
55 XGLTYPE: bytes
56 SOLARIS_XHDTYPE: bytes
57
58 USTAR_FORMAT: int
59 GNU_FORMAT: int
60 PAX_FORMAT: int
61 DEFAULT_FORMAT: int
62
63 # tarfile constants
64
65 SUPPORTED_TYPES: Tuple[bytes, ...]
66 REGULAR_TYPES: Tuple[bytes, ...]
67 GNU_TYPES: Tuple[bytes, ...]
68 PAX_FIELDS: Tuple[str, ...]
69 PAX_NUMBER_FIELDS: dict[str, type]
70 PAX_NAME_FIELDS: set[str]
71
72 ENCODING: str
73
74 def open(
75     name: StrOrBytesPath | None = ...,
76     mode: str = ...,
77     fileobj: IO[bytes] | None = ...,  # depends on mode
78     bufsize: int = ...,
79     *,
80     format: int | None = ...,
81     tarinfo: Type[TarInfo] | None = ...,
82     dereference: bool | None = ...,
83     ignore_zeros: bool | None = ...,
84     encoding: str | None = ...,
85     errors: str = ...,
86     pax_headers: Mapping[str, str] | None = ...,
87     debug: int | None = ...,
88     errorlevel: int | None = ...,
89     compresslevel: int | None = ...,
90 ) -> TarFile: ...
91
92 class ExFileObject(io.BufferedReader):
93     def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ...
94
95 _list = list  # conflicts with method name
96
97 class TarFile:
98     OPEN_METH: Mapping[str, str]
99     name: StrOrBytesPath | None
100     mode: Literal["r", "a", "w", "x"]
101     fileobj: _Fileobj | None
102     format: int | None
103     tarinfo: Type[TarInfo]
104     dereference: bool | None
105     ignore_zeros: bool | None
106     encoding: str | None
107     errors: str
108     fileobject: Type[ExFileObject]
109     pax_headers: Mapping[str, str] | None
110     debug: int | None
111     errorlevel: int | None
112     offset: int  # undocumented
113     def __init__(
114         self,
115         name: StrOrBytesPath | None = ...,
116         mode: Literal["r", "a", "w", "x"] = ...,
117         fileobj: _Fileobj | None = ...,
118         format: int | None = ...,
119         tarinfo: Type[TarInfo] | None = ...,
120         dereference: bool | None = ...,
121         ignore_zeros: bool | None = ...,
122         encoding: str | None = ...,
123         errors: str = ...,
124         pax_headers: Mapping[str, str] | None = ...,
125         debug: int | None = ...,
126         errorlevel: int | None = ...,
127         copybufsize: int | None = ...,  # undocumented
128     ) -> None: ...
129     def __enter__(self: Self) -> Self: ...
130     def __exit__(
131         self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
132     ) -> None: ...
133     def __iter__(self) -> Iterator[TarInfo]: ...
134     @classmethod
135     def open(
136         cls: Type[_TF],
137         name: StrOrBytesPath | None = ...,
138         mode: str = ...,
139         fileobj: IO[bytes] | None = ...,  # depends on mode
140         bufsize: int = ...,
141         *,
142         format: int | None = ...,
143         tarinfo: Type[TarInfo] | None = ...,
144         dereference: bool | None = ...,
145         ignore_zeros: bool | None = ...,
146         encoding: str | None = ...,
147         errors: str = ...,
148         pax_headers: Mapping[str, str] | None = ...,
149         debug: int | None = ...,
150         errorlevel: int | None = ...,
151     ) -> _TF: ...
152     @classmethod
153     def taropen(
154         cls: Type[_TF],
155         name: StrOrBytesPath | None,
156         mode: Literal["r", "a", "w", "x"] = ...,
157         fileobj: _Fileobj | None = ...,
158         *,
159         compresslevel: int = ...,
160         format: int | None = ...,
161         tarinfo: Type[TarInfo] | None = ...,
162         dereference: bool | None = ...,
163         ignore_zeros: bool | None = ...,
164         encoding: str | None = ...,
165         pax_headers: Mapping[str, str] | None = ...,
166         debug: int | None = ...,
167         errorlevel: int | None = ...,
168     ) -> _TF: ...
169     @overload
170     @classmethod
171     def gzopen(
172         cls: Type[_TF],
173         name: StrOrBytesPath | None,
174         mode: Literal["r"] = ...,
175         fileobj: _GzipReadableFileobj | None = ...,
176         compresslevel: int = ...,
177         *,
178         format: int | None = ...,
179         tarinfo: Type[TarInfo] | None = ...,
180         dereference: bool | None = ...,
181         ignore_zeros: bool | None = ...,
182         encoding: str | None = ...,
183         pax_headers: Mapping[str, str] | None = ...,
184         debug: int | None = ...,
185         errorlevel: int | None = ...,
186     ) -> _TF: ...
187     @overload
188     @classmethod
189     def gzopen(
190         cls: Type[_TF],
191         name: StrOrBytesPath | None,
192         mode: Literal["w", "x"],
193         fileobj: _GzipWritableFileobj | None = ...,
194         compresslevel: int = ...,
195         *,
196         format: int | None = ...,
197         tarinfo: Type[TarInfo] | None = ...,
198         dereference: bool | None = ...,
199         ignore_zeros: bool | None = ...,
200         encoding: str | None = ...,
201         pax_headers: Mapping[str, str] | None = ...,
202         debug: int | None = ...,
203         errorlevel: int | None = ...,
204     ) -> _TF: ...
205     @overload
206     @classmethod
207     def bz2open(
208         cls: Type[_TF],
209         name: StrOrBytesPath | None,
210         mode: Literal["w", "x"],
211         fileobj: _Bz2WritableFileobj | None = ...,
212         compresslevel: int = ...,
213         *,
214         format: int | None = ...,
215         tarinfo: Type[TarInfo] | None = ...,
216         dereference: bool | None = ...,
217         ignore_zeros: bool | None = ...,
218         encoding: str | None = ...,
219         pax_headers: Mapping[str, str] | None = ...,
220         debug: int | None = ...,
221         errorlevel: int | None = ...,
222     ) -> _TF: ...
223     @overload
224     @classmethod
225     def bz2open(
226         cls: Type[_TF],
227         name: StrOrBytesPath | None,
228         mode: Literal["r"] = ...,
229         fileobj: _Bz2ReadableFileobj | None = ...,
230         compresslevel: int = ...,
231         *,
232         format: int | None = ...,
233         tarinfo: Type[TarInfo] | None = ...,
234         dereference: bool | None = ...,
235         ignore_zeros: bool | None = ...,
236         encoding: str | None = ...,
237         pax_headers: Mapping[str, str] | None = ...,
238         debug: int | None = ...,
239         errorlevel: int | None = ...,
240     ) -> _TF: ...
241     @classmethod
242     def xzopen(
243         cls: Type[_TF],
244         name: StrOrBytesPath | None,
245         mode: Literal["r", "w", "x"] = ...,
246         fileobj: IO[bytes] | None = ...,
247         preset: int | None = ...,
248         *,
249         format: int | None = ...,
250         tarinfo: Type[TarInfo] | None = ...,
251         dereference: bool | None = ...,
252         ignore_zeros: bool | None = ...,
253         encoding: str | None = ...,
254         pax_headers: Mapping[str, str] | None = ...,
255         debug: int | None = ...,
256         errorlevel: int | None = ...,
257     ) -> _TF: ...
258     def getmember(self, name: str) -> TarInfo: ...
259     def getmembers(self) -> _list[TarInfo]: ...
260     def getnames(self) -> _list[str]: ...
261     def list(self, verbose: bool = ..., *, members: _list[TarInfo] | None = ...) -> None: ...
262     def next(self) -> TarInfo | None: ...
263     def extractall(
264         self, path: StrOrBytesPath = ..., members: Iterable[TarInfo] | None = ..., *, numeric_owner: bool = ...
265     ) -> None: ...
266     def extract(
267         self, member: str | TarInfo, path: StrOrBytesPath = ..., set_attrs: bool = ..., *, numeric_owner: bool = ...
268     ) -> None: ...
269     def _extract_member(
270         self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = ..., numeric_owner: bool = ...
271     ) -> None: ...  # undocumented
272     def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ...
273     def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
274     def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
275     def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
276     def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
277     def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
278     def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
279     def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ...  # undocumented
280     def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
281     def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ...  # undocumented
282     if sys.version_info >= (3, 7):
283         def add(
284             self,
285             name: StrPath,
286             arcname: StrPath | None = ...,
287             recursive: bool = ...,
288             *,
289             filter: Callable[[TarInfo], TarInfo | None] | None = ...,
290         ) -> None: ...
291     else:
292         def add(
293             self,
294             name: StrPath,
295             arcname: StrPath | None = ...,
296             recursive: bool = ...,
297             exclude: Callable[[str], bool] | None = ...,
298             *,
299             filter: Callable[[TarInfo], TarInfo | None] | None = ...,
300         ) -> None: ...
301     def addfile(self, tarinfo: TarInfo, fileobj: IO[bytes] | None = ...) -> None: ...
302     def gettarinfo(self, name: str | None = ..., arcname: str | None = ..., fileobj: IO[bytes] | None = ...) -> TarInfo: ...
303     def close(self) -> None: ...
304
305 if sys.version_info >= (3, 9):
306     def is_tarfile(name: StrOrBytesPath | IO[bytes]) -> bool: ...
307
308 else:
309     def is_tarfile(name: StrOrBytesPath) -> bool: ...
310
311 if sys.version_info < (3, 8):
312     def filemode(mode: int) -> str: ...  # undocumented
313
314 class TarError(Exception): ...
315 class ReadError(TarError): ...
316 class CompressionError(TarError): ...
317 class StreamError(TarError): ...
318 class ExtractError(TarError): ...
319 class HeaderError(TarError): ...
320
321 class TarInfo:
322     name: str
323     path: str
324     size: int
325     mtime: int
326     chksum: int
327     devmajor: int
328     devminor: int
329     offset: int
330     offset_data: int
331     sparse: bytes | None
332     tarfile: TarFile | None
333     mode: int
334     type: bytes
335     linkname: str
336     uid: int
337     gid: int
338     uname: str
339     gname: str
340     pax_headers: Mapping[str, str]
341     def __init__(self, name: str = ...) -> None: ...
342     @classmethod
343     def frombuf(cls, buf: bytes, encoding: str, errors: str) -> TarInfo: ...
344     @classmethod
345     def fromtarfile(cls, tarfile: TarFile) -> TarInfo: ...
346     @property
347     def linkpath(self) -> str: ...
348     @linkpath.setter
349     def linkpath(self, linkname: str) -> None: ...
350     def get_info(self) -> Mapping[str, str | int | bytes | Mapping[str, str]]: ...
351     def tobuf(self, format: int | None = ..., encoding: str | None = ..., errors: str = ...) -> bytes: ...
352     def create_ustar_header(
353         self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str
354     ) -> bytes: ...
355     def create_gnu_header(
356         self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str
357     ) -> bytes: ...
358     def create_pax_header(self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str) -> bytes: ...
359     @classmethod
360     def create_pax_global_header(cls, pax_headers: Mapping[str, str]) -> bytes: ...
361     def isfile(self) -> bool: ...
362     def isreg(self) -> bool: ...
363     def issparse(self) -> bool: ...
364     def isdir(self) -> bool: ...
365     def issym(self) -> bool: ...
366     def islnk(self) -> bool: ...
367     def ischr(self) -> bool: ...
368     def isblk(self) -> bool: ...
369     def isfifo(self) -> bool: ...
370     def isdev(self) -> bool: ...