Debian Codegraph @

src/python/backports/zstd/tarfile.pyi

raw symbols SCIP
1 import bz2
2 import io
3 from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer
4 from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list"
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, ClassVar, Final, Literal, Protocol, TypeAlias, overload, type_check_only
9 from typing_extensions import Self, deprecated
10
11 from backports.zstd import ZstdDict
12
13 __all__ = [
14 "TarFile",
15 "TarInfo",
16 "is_tarfile",
17 "TarError",
18 "ReadError",
19 "CompressionError",
20 "StreamError",
21 "ExtractError",
22 "HeaderError",
23 "ENCODING",
24 "USTAR_FORMAT",
25 "GNU_FORMAT",
26 "PAX_FORMAT",
27 "DEFAULT_FORMAT",
28 "open",
29 "fully_trusted_filter",
30 "data_filter",
31 "tar_filter",
32 "FilterError",
33 "AbsoluteLinkError",
34 "OutsideDestinationError",
35 "SpecialFileError",
36 "AbsolutePathError",
37 "LinkOutsideDestinationError",
38 "LinkFallbackError",
39 ]
40
41 _FilterFunction: TypeAlias = Callable[[TarInfo, str], TarInfo | None]
42 _TarfileFilter: TypeAlias = Literal["fully_trusted", "tar", "data"] | _FilterFunction
43
44 @type_check_only
45 class _Fileobj(Protocol):
46 def read(self, size: int, /) -> bytes: ...
47 def write(self, b: bytes, /) -> object: ...
48 def tell(self) -> int: ...
49 def seek(self, pos: int, /) -> object: ...
50 def close(self) -> object: ...
51 # Optional fields:
52 # name: str | bytes
53 # mode: Literal["rb", "r+b", "wb", "xb"]
54
55 @type_check_only
56 class _Bz2ReadableFileobj(bz2._ReadableFileobj):
57 def close(self) -> object: ...
58
59 @type_check_only
60 class _Bz2WritableFileobj(bz2._WritableFileobj):
61 def close(self) -> object: ...
62
63 # tar constants
64 NUL: Final = b"\0"
65 BLOCKSIZE: Final = 512
66 RECORDSIZE: Final = 10240
67 GNU_MAGIC: Final = b"ustar \0"
68 POSIX_MAGIC: Final = b"ustar\x0000"
69
70 LENGTH_NAME: Final = 100
71 LENGTH_LINK: Final = 100
72 LENGTH_PREFIX: Final = 155
73
74 REGTYPE: Final = b"0"
75 AREGTYPE: Final = b"\0"
76 LNKTYPE: Final = b"1"
77 SYMTYPE: Final = b"2"
78 CHRTYPE: Final = b"3"
79 BLKTYPE: Final = b"4"
80 DIRTYPE: Final = b"5"
81 FIFOTYPE: Final = b"6"
82 CONTTYPE: Final = b"7"
83
84 GNUTYPE_LONGNAME: Final = b"L"
85 GNUTYPE_LONGLINK: Final = b"K"
86 GNUTYPE_SPARSE: Final = b"S"
87
88 XHDTYPE: Final = b"x"
89 XGLTYPE: Final = b"g"
90 SOLARIS_XHDTYPE: Final = b"X"
91
92 _TarFormat: TypeAlias = Literal[0, 1, 2] # does not exist at runtime
93 USTAR_FORMAT: Final = 0
94 GNU_FORMAT: Final = 1
95 PAX_FORMAT: Final = 2
96 DEFAULT_FORMAT: Final = PAX_FORMAT
97
98 # tarfile constants
99
100 SUPPORTED_TYPES: Final[tuple[bytes, ...]]
101 REGULAR_TYPES: Final[tuple[bytes, ...]]
102 GNU_TYPES: Final[tuple[bytes, ...]]
103 PAX_FIELDS: Final[tuple[str, ...]]
104 PAX_NUMBER_FIELDS: Final[dict[str, type]]
105 PAX_NAME_FIELDS: Final[set[str]]
106
107 ENCODING: Final[str]
108
109 class ExFileObject(io.BufferedReader): # undocumented
110 def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ...
111
112 class TarFile:
113 OPEN_METH: ClassVar[Mapping[str, str]]
114 name: StrOrBytesPath | None
115 mode: Literal["r", "a", "w", "x"]
116 fileobj: _Fileobj
117 format: _TarFormat
118 tarinfo: type[TarInfo]
119 dereference: bool
120 ignore_zeros: bool
121 encoding: str
122 errors: str
123 fileobject: type[ExFileObject] # undocumented
124 pax_headers: Mapping[str, str]
125 debug: Literal[0, 1, 2, 3]
126 errorlevel: Literal[0, 1, 2]
127 offset: int # undocumented
128 extraction_filter: _FilterFunction | None
129 stream: bool
130 def __init__(
131 self,
132 name: StrOrBytesPath | None = None,
133 mode: Literal["r", "a", "w", "x"] = "r",
134 fileobj: _Fileobj | None = None,
135 format: int | None = None,
136 tarinfo: type[TarInfo] | None = None,
137 dereference: bool | None = None,
138 ignore_zeros: bool | None = None,
139 encoding: str | None = None,
140 errors: str = "surrogateescape",
141 pax_headers: Mapping[str, str] | None = None,
142 debug: Literal[0, 1, 2, 3] | None = None, # default 0
143 errorlevel: Literal[0, 1, 2] | None = None, # default 1
144 copybufsize: int | None = None, # undocumented
145 stream: bool = False,
146 ) -> None: ...
147
148 def __enter__(self) -> Self: ...
149 def __exit__(
150 self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
151 ) -> None: ...
152 def __iter__(self) -> Iterator[TarInfo]: ...
153 @overload
154 @classmethod
155 def open(
156 cls,
157 name: StrOrBytesPath | None = None,
158 mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r",
159 fileobj: _Fileobj | None = None,
160 bufsize: int = 10240,
161 *,
162 format: int | None = ...,
163 tarinfo: type[TarInfo] | None = ...,
164 dereference: bool | None = ...,
165 ignore_zeros: bool | None = ...,
166 encoding: str | None = ...,
167 errors: str = ...,
168 pax_headers: Mapping[str, str] | None = ...,
169 debug: Literal[0, 1, 2, 3] | None = None, # default 0
170 errorlevel: Literal[0, 1, 2] | None = None, # default 1
171 ) -> Self: ...
172
173 @overload
174 @classmethod
175 def open(
176 cls,
177 name: StrOrBytesPath | None,
178 mode: Literal["r:zst"],
179 fileobj: _Fileobj | None = None,
180 bufsize: int = 10240,
181 *,
182 format: int | None = ...,
183 tarinfo: type[TarInfo] | None = ...,
184 dereference: bool | None = ...,
185 ignore_zeros: bool | None = ...,
186 encoding: str | None = ...,
187 errors: str = ...,
188 pax_headers: Mapping[str, str] | None = ...,
189 debug: Literal[0, 1, 2, 3] | None = None, # default 0
190 errorlevel: Literal[0, 1, 2] | None = None, # default 1
191 level: None = None,
192 options: Mapping[int, int] | None = None,
193 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
194 ) -> Self: ...
195
196 @overload
197 @classmethod
198 def open(
199 cls,
200 name: StrOrBytesPath | None,
201 mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
202 fileobj: _Fileobj | None = None,
203 bufsize: int = 10240,
204 *,
205 format: int | None = ...,
206 tarinfo: type[TarInfo] | None = ...,
207 dereference: bool | None = ...,
208 ignore_zeros: bool | None = ...,
209 encoding: str | None = ...,
210 errors: str = ...,
211 pax_headers: Mapping[str, str] | None = ...,
212 debug: Literal[0, 1, 2, 3] | None = None, # default 0
213 errorlevel: Literal[0, 1, 2] | None = None, # default 1
214 ) -> Self: ...
215 @overload
216 @classmethod
217 def open(
218 cls,
219 name: StrOrBytesPath | None = None,
220 *,
221 mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
222 fileobj: _Fileobj | None = None,
223 bufsize: int = 10240,
224 format: int | None = ...,
225 tarinfo: type[TarInfo] | None = ...,
226 dereference: bool | None = ...,
227 ignore_zeros: bool | None = ...,
228 encoding: str | None = ...,
229 errors: str = ...,
230 pax_headers: Mapping[str, str] | None = ...,
231 debug: Literal[0, 1, 2, 3] | None = None, # default 0
232 errorlevel: Literal[0, 1, 2] | None = None, # default 1
233 ) -> Self: ...
234 @overload
235 @classmethod
236 def open(
237 cls,
238 name: StrOrBytesPath | None,
239 mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
240 fileobj: _Fileobj | None = None,
241 bufsize: int = 10240,
242 *,
243 format: int | None = ...,
244 tarinfo: type[TarInfo] | None = ...,
245 dereference: bool | None = ...,
246 ignore_zeros: bool | None = ...,
247 encoding: str | None = ...,
248 errors: str = ...,
249 pax_headers: Mapping[str, str] | None = ...,
250 debug: Literal[0, 1, 2, 3] | None = None, # default 0
251 errorlevel: Literal[0, 1, 2] | None = None, # default 1
252 compresslevel: int = 9,
253 ) -> Self: ...
254 @overload
255 @classmethod
256 def open(
257 cls,
258 name: StrOrBytesPath | None = None,
259 *,
260 mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
261 fileobj: _Fileobj | None = None,
262 bufsize: int = 10240,
263 format: int | None = ...,
264 tarinfo: type[TarInfo] | None = ...,
265 dereference: bool | None = ...,
266 ignore_zeros: bool | None = ...,
267 encoding: str | None = ...,
268 errors: str = ...,
269 pax_headers: Mapping[str, str] | None = ...,
270 debug: Literal[0, 1, 2, 3] | None = None, # default 0
271 errorlevel: Literal[0, 1, 2] | None = None, # default 1
272 compresslevel: int = 9,
273 ) -> Self: ...
274 @overload
275 @classmethod
276 def open(
277 cls,
278 name: StrOrBytesPath | None,
279 mode: Literal["x:xz", "w:xz"],
280 fileobj: _Fileobj | None = None,
281 bufsize: int = 10240,
282 *,
283 format: int | None = ...,
284 tarinfo: type[TarInfo] | None = ...,
285 dereference: bool | None = ...,
286 ignore_zeros: bool | None = ...,
287 encoding: str | None = ...,
288 errors: str = ...,
289 pax_headers: Mapping[str, str] | None = ...,
290 debug: Literal[0, 1, 2, 3] | None = None, # default 0
291 errorlevel: Literal[0, 1, 2] | None = None, # default 1
292 preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
293 ) -> Self: ...
294 @overload
295 @classmethod
296 def open(
297 cls,
298 name: StrOrBytesPath | None = None,
299 *,
300 mode: Literal["x:xz", "w:xz"],
301 fileobj: _Fileobj | None = None,
302 bufsize: int = 10240,
303 format: int | None = ...,
304 tarinfo: type[TarInfo] | None = ...,
305 dereference: bool | None = ...,
306 ignore_zeros: bool | None = ...,
307 encoding: str | None = ...,
308 errors: str = ...,
309 pax_headers: Mapping[str, str] | None = ...,
310 debug: Literal[0, 1, 2, 3] | None = None, # default 0
311 errorlevel: Literal[0, 1, 2] | None = None, # default 1
312 preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
313 ) -> Self: ...
314 @overload
315 @classmethod
316 def open(
317 cls,
318 name: StrOrBytesPath | None,
319 mode: Literal["x:zst", "w:zst"],
320 fileobj: _Fileobj | None = None,
321 bufsize: int = 10240,
322 *,
323 format: int | None = ...,
324 tarinfo: type[TarInfo] | None = ...,
325 dereference: bool | None = ...,
326 ignore_zeros: bool | None = ...,
327 encoding: str | None = ...,
328 errors: str = ...,
329 pax_headers: Mapping[str, str] | None = ...,
330 debug: Literal[0, 1, 2, 3] | None = None, # default 0
331 errorlevel: Literal[0, 1, 2] | None = None, # default 1
332 options: Mapping[int, int] | None = None,
333 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
334 ) -> Self: ...
335 @overload
336 @classmethod
337 def open(
338 cls,
339 name: StrOrBytesPath | None = None,
340 *,
341 mode: Literal["x:zst", "w:zst"],
342 fileobj: _Fileobj | None = None,
343 bufsize: int = 10240,
344 format: int | None = ...,
345 tarinfo: type[TarInfo] | None = ...,
346 dereference: bool | None = ...,
347 ignore_zeros: bool | None = ...,
348 encoding: str | None = ...,
349 errors: str = ...,
350 pax_headers: Mapping[str, str] | None = ...,
351 debug: Literal[0, 1, 2, 3] | None = None, # default 0
352 errorlevel: Literal[0, 1, 2] | None = None, # default 1
353 options: Mapping[int, int] | None = None,
354 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
355 ) -> Self: ...
356
357 @overload
358 @classmethod
359 def open(
360 cls,
361 name: StrOrBytesPath | ReadableBuffer | None,
362 mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "r|zst"],
363 fileobj: _Fileobj | None = None,
364 bufsize: int = 10240,
365 *,
366 format: int | None = ...,
367 tarinfo: type[TarInfo] | None = ...,
368 dereference: bool | None = ...,
369 ignore_zeros: bool | None = ...,
370 encoding: str | None = ...,
371 errors: str = ...,
372 pax_headers: Mapping[str, str] | None = ...,
373 debug: Literal[0, 1, 2, 3] | None = None, # default 0
374 errorlevel: Literal[0, 1, 2] | None = None, # default 1
375 ) -> Self: ...
376 @overload
377 @classmethod
378 def open(
379 cls,
380 name: StrOrBytesPath | ReadableBuffer | None = None,
381 *,
382 mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "r|zst"],
383 fileobj: _Fileobj | None = None,
384 bufsize: int = 10240,
385 format: int | None = ...,
386 tarinfo: type[TarInfo] | None = ...,
387 dereference: bool | None = ...,
388 ignore_zeros: bool | None = ...,
389 encoding: str | None = ...,
390 errors: str = ...,
391 pax_headers: Mapping[str, str] | None = ...,
392 debug: Literal[0, 1, 2, 3] | None = None, # default 0
393 errorlevel: Literal[0, 1, 2] | None = None, # default 1
394 ) -> Self: ...
395 @overload
396 @classmethod
397 def open(
398 cls,
399 name: StrOrBytesPath | WriteableBuffer | None,
400 mode: Literal["w|", "w|xz", "w|zst"],
401 fileobj: _Fileobj | None = None,
402 bufsize: int = 10240,
403 *,
404 format: int | None = ...,
405 tarinfo: type[TarInfo] | None = ...,
406 dereference: bool | None = ...,
407 ignore_zeros: bool | None = ...,
408 encoding: str | None = ...,
409 errors: str = ...,
410 pax_headers: Mapping[str, str] | None = ...,
411 debug: Literal[0, 1, 2, 3] | None = None, # default 0
412 errorlevel: Literal[0, 1, 2] | None = None, # default 1
413 ) -> Self: ...
414 @overload
415 @classmethod
416 def open(
417 cls,
418 name: StrOrBytesPath | WriteableBuffer | None = None,
419 *,
420 mode: Literal["w|", "w|xz", "w|zst"],
421 fileobj: _Fileobj | None = None,
422 bufsize: int = 10240,
423 format: int | None = ...,
424 tarinfo: type[TarInfo] | None = ...,
425 dereference: bool | None = ...,
426 ignore_zeros: bool | None = ...,
427 encoding: str | None = ...,
428 errors: str = ...,
429 pax_headers: Mapping[str, str] | None = ...,
430 debug: Literal[0, 1, 2, 3] | None = None, # default 0
431 errorlevel: Literal[0, 1, 2] | None = None, # default 1
432 ) -> Self: ...
433 @overload
434 @classmethod
435 def open(
436 cls,
437 name: StrOrBytesPath | WriteableBuffer | None,
438 mode: Literal["w|gz", "w|bz2"],
439 fileobj: _Fileobj | None = None,
440 bufsize: int = 10240,
441 *,
442 format: int | None = ...,
443 tarinfo: type[TarInfo] | None = ...,
444 dereference: bool | None = ...,
445 ignore_zeros: bool | None = ...,
446 encoding: str | None = ...,
447 errors: str = ...,
448 pax_headers: Mapping[str, str] | None = ...,
449 debug: Literal[0, 1, 2, 3] | None = None, # default 0
450 errorlevel: Literal[0, 1, 2] | None = None, # default 1
451 compresslevel: int = 9,
452 ) -> Self: ...
453 @overload
454 @classmethod
455 def open(
456 cls,
457 name: StrOrBytesPath | WriteableBuffer | None = None,
458 *,
459 mode: Literal["w|gz", "w|bz2"],
460 fileobj: _Fileobj | None = None,
461 bufsize: int = 10240,
462 format: int | None = ...,
463 tarinfo: type[TarInfo] | None = ...,
464 dereference: bool | None = ...,
465 ignore_zeros: bool | None = ...,
466 encoding: str | None = ...,
467 errors: str = ...,
468 pax_headers: Mapping[str, str] | None = ...,
469 debug: Literal[0, 1, 2, 3] | None = None, # default 0
470 errorlevel: Literal[0, 1, 2] | None = None, # default 1
471 compresslevel: int = 9,
472 ) -> Self: ...
473
474 @classmethod
475 def taropen(
476 cls,
477 name: StrOrBytesPath | None,
478 mode: Literal["r", "a", "w", "x"] = "r",
479 fileobj: _Fileobj | None = None,
480 *,
481 compresslevel: int = ...,
482 format: int | None = ...,
483 tarinfo: type[TarInfo] | None = ...,
484 dereference: bool | None = ...,
485 ignore_zeros: bool | None = ...,
486 encoding: str | None = ...,
487 pax_headers: Mapping[str, str] | None = ...,
488 debug: Literal[0, 1, 2, 3] | None = None, # default 0
489 errorlevel: Literal[0, 1, 2] | None = None, # default 1
490 ) -> Self: ...
491
492 @overload
493 @classmethod
494 def gzopen(
495 cls,
496 name: StrOrBytesPath | None,
497 mode: Literal["r"] = "r",
498 fileobj: _GzipReadableFileobj | None = None,
499 compresslevel: int = 9,
500 *,
501 format: int | None = ...,
502 tarinfo: type[TarInfo] | None = ...,
503 dereference: bool | None = ...,
504 ignore_zeros: bool | None = ...,
505 encoding: str | None = ...,
506 pax_headers: Mapping[str, str] | None = ...,
507 debug: Literal[0, 1, 2, 3] | None = None, # default 0
508 errorlevel: Literal[0, 1, 2] | None = None, # default 1
509 ) -> Self: ...
510 @overload
511 @classmethod
512 def gzopen(
513 cls,
514 name: StrOrBytesPath | None,
515 mode: Literal["w", "x"],
516 fileobj: _GzipWritableFileobj | None = None,
517 compresslevel: int = 9,
518 *,
519 format: int | None = ...,
520 tarinfo: type[TarInfo] | None = ...,
521 dereference: bool | None = ...,
522 ignore_zeros: bool | None = ...,
523 encoding: str | None = ...,
524 pax_headers: Mapping[str, str] | None = ...,
525 debug: Literal[0, 1, 2, 3] | None = None, # default 0
526 errorlevel: Literal[0, 1, 2] | None = None, # default 1
527 ) -> Self: ...
528
529 @overload
530 @classmethod
531 def bz2open(
532 cls,
533 name: StrOrBytesPath | None,
534 mode: Literal["w", "x"],
535 fileobj: _Bz2WritableFileobj | None = None,
536 compresslevel: int = 9,
537 *,
538 format: int | None = ...,
539 tarinfo: type[TarInfo] | None = ...,
540 dereference: bool | None = ...,
541 ignore_zeros: bool | None = ...,
542 encoding: str | None = ...,
543 pax_headers: Mapping[str, str] | None = ...,
544 debug: Literal[0, 1, 2, 3] | None = None, # default 0
545 errorlevel: Literal[0, 1, 2] | None = None, # default 1
546 ) -> Self: ...
547 @overload
548 @classmethod
549 def bz2open(
550 cls,
551 name: StrOrBytesPath | None,
552 mode: Literal["r"] = "r",
553 fileobj: _Bz2ReadableFileobj | None = None,
554 compresslevel: int = 9,
555 *,
556 format: int | None = ...,
557 tarinfo: type[TarInfo] | None = ...,
558 dereference: bool | None = ...,
559 ignore_zeros: bool | None = ...,
560 encoding: str | None = ...,
561 pax_headers: Mapping[str, str] | None = ...,
562 debug: Literal[0, 1, 2, 3] | None = None, # default 0
563 errorlevel: Literal[0, 1, 2] | None = None, # default 1
564 ) -> Self: ...
565
566 @classmethod
567 def xzopen(
568 cls,
569 name: StrOrBytesPath | None,
570 mode: Literal["r", "w", "x"] = "r",
571 fileobj: IO[bytes] | None = None,
572 preset: int | None = None,
573 *,
574 format: int | None = ...,
575 tarinfo: type[TarInfo] | None = ...,
576 dereference: bool | None = ...,
577 ignore_zeros: bool | None = ...,
578 encoding: str | None = ...,
579 pax_headers: Mapping[str, str] | None = ...,
580 debug: Literal[0, 1, 2, 3] | None = None, # default 0
581 errorlevel: Literal[0, 1, 2] | None = None, # default 1
582 ) -> Self: ...
583 @overload
584 @classmethod
585 def zstopen(
586 cls,
587 name: StrOrBytesPath | None,
588 mode: Literal["r"] = "r",
589 fileobj: IO[bytes] | None = None,
590 level: None = None,
591 options: Mapping[int, int] | None = None,
592 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
593 *,
594 format: int | None = ...,
595 tarinfo: type[TarInfo] | None = ...,
596 dereference: bool | None = ...,
597 ignore_zeros: bool | None = ...,
598 encoding: str | None = ...,
599 pax_headers: Mapping[str, str] | None = ...,
600 debug: Literal[0, 1, 2, 3] | None = None, # default 0
601 errorlevel: Literal[0, 1, 2] | None = None, # default 1
602 ) -> Self: ...
603 @overload
604 @classmethod
605 def zstopen(
606 cls,
607 name: StrOrBytesPath | None,
608 mode: Literal["w", "x"],
609 fileobj: IO[bytes] | None = None,
610 level: int | None = None,
611 options: Mapping[int, int] | None = None,
612 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
613 *,
614 format: int | None = ...,
615 tarinfo: type[TarInfo] | None = ...,
616 dereference: bool | None = ...,
617 ignore_zeros: bool | None = ...,
618 encoding: str | None = ...,
619 pax_headers: Mapping[str, str] | None = ...,
620 debug: Literal[0, 1, 2, 3] | None = None, # default 0
621 errorlevel: Literal[0, 1, 2] | None = None, # default 1
622 ) -> Self: ...
623
624 def getmember(self, name: str) -> TarInfo: ...
625 def getmembers(self) -> _list[TarInfo]: ...
626 def getnames(self) -> _list[str]: ...
627 def list(self, verbose: bool = True, *, members: Iterable[TarInfo] | None = None) -> None: ...
628 def next(self) -> TarInfo | None: ...
629 # Calling this method without `filter` is deprecated, but it may be set either on the class or in an
630 # individual call, so we can't mark it as @deprecated here.
631 def extractall(
632 self,
633 path: StrOrBytesPath = ".",
634 members: Iterable[TarInfo] | None = None,
635 *,
636 numeric_owner: bool = False,
637 filter: _TarfileFilter | None = None,
638 ) -> None: ...
639 # Same situation as for `extractall`.
640 def extract(
641 self,
642 member: str | TarInfo,
643 path: StrOrBytesPath = "",
644 set_attrs: bool = True,
645 *,
646 numeric_owner: bool = False,
647 filter: _TarfileFilter | None = None,
648 ) -> None: ...
649 def _extract_member(
650 self,
651 tarinfo: TarInfo,
652 targetpath: str,
653 set_attrs: bool = True,
654 numeric_owner: bool = False,
655 *,
656 filter_function: _FilterFunction | None = None,
657 extraction_root: str | None = None,
658 ) -> None: ... # undocumented
659 def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ...
660 def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
661 def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
662 def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
663 def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
664 def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
665 def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
666 def makelink_with_filter(
667 self, tarinfo: TarInfo, targetpath: StrOrBytesPath, filter_function: _FilterFunction, extraction_root: str
668 ) -> None: ... # undocumented
669 def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented
670 def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
671 def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
672 def add(
673 self,
674 name: StrPath,
675 arcname: StrPath | None = None,
676 recursive: bool = True,
677 *,
678 filter: Callable[[TarInfo], TarInfo | None] | None = None,
679 ) -> None: ...
680 def addfile(self, tarinfo: TarInfo, fileobj: SupportsRead[bytes] | None = None) -> None: ...
681 def gettarinfo(
682 self, name: StrOrBytesPath | None = None, arcname: str | None = None, fileobj: IO[bytes] | None = None
683 ) -> TarInfo: ...
684 def close(self) -> None: ...
685
686 open = TarFile.open
687
688 def is_tarfile(name: StrOrBytesPath | IO[bytes]) -> bool: ...
689
690 class TarError(Exception): ...
691 class ReadError(TarError): ...
692 class CompressionError(TarError): ...
693 class StreamError(TarError): ...
694 class ExtractError(TarError): ...
695 class HeaderError(TarError): ...
696
697 class FilterError(TarError):
698 # This attribute is only set directly on the subclasses, but the documentation guarantees
699 # that it is always present on FilterError.
700 tarinfo: TarInfo
701
702 class AbsolutePathError(FilterError):
703 def __init__(self, tarinfo: TarInfo) -> None: ...
704
705 class OutsideDestinationError(FilterError):
706 def __init__(self, tarinfo: TarInfo, path: str) -> None: ...
707
708 class SpecialFileError(FilterError):
709 def __init__(self, tarinfo: TarInfo) -> None: ...
710
711 class AbsoluteLinkError(FilterError):
712 def __init__(self, tarinfo: TarInfo) -> None: ...
713
714 class LinkOutsideDestinationError(FilterError):
715 def __init__(self, tarinfo: TarInfo, path: str) -> None: ...
716
717 class LinkFallbackError(FilterError):
718 def __init__(self, tarinfo: TarInfo, path: str) -> None: ...
719
720 def fully_trusted_filter(member: TarInfo, dest_path: str) -> TarInfo: ...
721 def tar_filter(member: TarInfo, dest_path: str) -> TarInfo: ...
722 def data_filter(member: TarInfo, dest_path: str) -> TarInfo: ...
723
724 class TarInfo:
725 __slots__ = (
726 "name",
727 "mode",
728 "uid",
729 "gid",
730 "size",
731 "mtime",
732 "chksum",
733 "type",
734 "linkname",
735 "uname",
736 "gname",
737 "devmajor",
738 "devminor",
739 "offset",
740 "offset_data",
741 "pax_headers",
742 "sparse",
743 "_tarfile",
744 "_sparse_structs",
745 "_link_target",
746 )
747 name: str
748 path: str
749 size: int
750 mtime: int | float
751 chksum: int
752 devmajor: int
753 devminor: int
754 offset: int
755 offset_data: int
756 sparse: bytes | None
757 mode: int
758 type: bytes # usually one of the TYPE constants, but could be an arbitrary byte
759 linkname: str
760 uid: int
761 gid: int
762 uname: str
763 gname: str
764 pax_headers: Mapping[str, str]
765 def __init__(self, name: str = "") -> None: ...
766
767 @property
768 @deprecated("Deprecated; will be removed in Python 3.16.")
769 def tarfile(self) -> TarFile | None: ...
770 @tarfile.setter
771 @deprecated("Deprecated; will be removed in Python 3.16.")
772 def tarfile(self, tarfile: TarFile | None) -> None: ...
773
774 @classmethod
775 def frombuf(cls, buf: bytes | bytearray, encoding: str, errors: str) -> Self: ...
776 @classmethod
777 def fromtarfile(cls, tarfile: TarFile) -> Self: ...
778
779 @property
780 def linkpath(self) -> str: ...
781 @linkpath.setter
782 def linkpath(self, linkname: str) -> None: ...
783
784 def replace(
785 self,
786 *,
787 name: str = ...,
788 mtime: float = ...,
789 mode: int = ...,
790 linkname: str = ...,
791 uid: int = ...,
792 gid: int = ...,
793 uname: str = ...,
794 gname: str = ...,
795 deep: bool = True,
796 ) -> Self: ...
797 def get_info(self) -> Mapping[str, str | int | bytes | Mapping[str, str]]: ...
798 def tobuf(self, format: _TarFormat | None = 2, encoding: str | None = "utf-8", errors: str = "surrogateescape") -> bytes: ...
799 def create_ustar_header(
800 self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str
801 ) -> bytes: ...
802 def create_gnu_header(
803 self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str
804 ) -> bytes: ...
805 def create_pax_header(self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str) -> bytes: ...
806 @classmethod
807 def create_pax_global_header(cls, pax_headers: Mapping[str, str]) -> bytes: ...
808 def isfile(self) -> bool: ...
809 def isreg(self) -> bool: ...
810 def issparse(self) -> bool: ...
811 def isdir(self) -> bool: ...
812 def issym(self) -> bool: ...
813 def islnk(self) -> bool: ...
814 def ischr(self) -> bool: ...
815 def isblk(self) -> bool: ...
816 def isfifo(self) -> bool: ...
817 def isdev(self) -> bool: ...