Debian Codegraph @

src/python/backports/zstd/tarfile.pyi

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