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
11 _TF = TypeVar("_TF", bound=TarFile)
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: ...
21 # mode: Literal["rb", "r+b", "wb", "xb"]
23 class _Bz2ReadableFileobj(bz2._ReadableFileobj):
24 def close(self) -> object: ...
26 class _Bz2WritableFileobj(bz2._WritableFileobj):
27 def close(self) -> object: ...
50 GNUTYPE_LONGNAME: bytes
51 GNUTYPE_LONGLINK: bytes
56 SOLARIS_XHDTYPE: bytes
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]
75 name: StrOrBytesPath | None = ...,
77 fileobj: IO[bytes] | None = ..., # depends on mode
80 format: int | None = ...,
81 tarinfo: Type[TarInfo] | None = ...,
82 dereference: bool | None = ...,
83 ignore_zeros: bool | None = ...,
84 encoding: str | None = ...,
86 pax_headers: Mapping[str, str] | None = ...,
87 debug: int | None = ...,
88 errorlevel: int | None = ...,
89 compresslevel: int | None = ...,
92 class ExFileObject(io.BufferedReader):
93 def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ...
95 _list = list # conflicts with method name
98 OPEN_METH: Mapping[str, str]
99 name: StrOrBytesPath | None
100 mode: Literal["r", "a", "w", "x"]
101 fileobj: _Fileobj | None
103 tarinfo: Type[TarInfo]
104 dereference: bool | None
105 ignore_zeros: bool | None
108 fileobject: Type[ExFileObject]
109 pax_headers: Mapping[str, str] | None
111 errorlevel: int | None
112 offset: int # undocumented
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 = ...,
124 pax_headers: Mapping[str, str] | None = ...,
125 debug: int | None = ...,
126 errorlevel: int | None = ...,
127 copybufsize: int | None = ..., # undocumented
129 def __enter__(self: Self) -> Self: ...
131 self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
133 def __iter__(self) -> Iterator[TarInfo]: ...
137 name: StrOrBytesPath | None = ...,
139 fileobj: IO[bytes] | None = ..., # depends on mode
142 format: int | None = ...,
143 tarinfo: Type[TarInfo] | None = ...,
144 dereference: bool | None = ...,
145 ignore_zeros: bool | None = ...,
146 encoding: str | None = ...,
148 pax_headers: Mapping[str, str] | None = ...,
149 debug: int | None = ...,
150 errorlevel: int | None = ...,
155 name: StrOrBytesPath | None,
156 mode: Literal["r", "a", "w", "x"] = ...,
157 fileobj: _Fileobj | None = ...,
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 = ...,
173 name: StrOrBytesPath | None,
174 mode: Literal["r"] = ...,
175 fileobj: _GzipReadableFileobj | None = ...,
176 compresslevel: int = ...,
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 = ...,
191 name: StrOrBytesPath | None,
192 mode: Literal["w", "x"],
193 fileobj: _GzipWritableFileobj | None = ...,
194 compresslevel: int = ...,
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 = ...,
209 name: StrOrBytesPath | None,
210 mode: Literal["w", "x"],
211 fileobj: _Bz2WritableFileobj | None = ...,
212 compresslevel: int = ...,
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 = ...,
227 name: StrOrBytesPath | None,
228 mode: Literal["r"] = ...,
229 fileobj: _Bz2ReadableFileobj | None = ...,
230 compresslevel: int = ...,
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 = ...,
244 name: StrOrBytesPath | None,
245 mode: Literal["r", "w", "x"] = ...,
246 fileobj: IO[bytes] | None = ...,
247 preset: int | None = ...,
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 = ...,
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: ...
264 self, path: StrOrBytesPath = ..., members: Iterable[TarInfo] | None = ..., *, numeric_owner: bool = ...
267 self, member: str | TarInfo, path: StrOrBytesPath = ..., set_attrs: bool = ..., *, numeric_owner: bool = ...
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):
286 arcname: StrPath | None = ...,
287 recursive: bool = ...,
289 filter: Callable[[TarInfo], TarInfo | None] | None = ...,
295 arcname: StrPath | None = ...,
296 recursive: bool = ...,
297 exclude: Callable[[str], bool] | None = ...,
299 filter: Callable[[TarInfo], TarInfo | None] | 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: ...
305 if sys.version_info >= (3, 9):
306 def is_tarfile(name: StrOrBytesPath | IO[bytes]) -> bool: ...
309 def is_tarfile(name: StrOrBytesPath) -> bool: ...
311 if sys.version_info < (3, 8):
312 def filemode(mode: int) -> str: ... # undocumented
314 class TarError(Exception): ...
315 class ReadError(TarError): ...
316 class CompressionError(TarError): ...
317 class StreamError(TarError): ...
318 class ExtractError(TarError): ...
319 class HeaderError(TarError): ...
332 tarfile: TarFile | None
340 pax_headers: Mapping[str, str]
341 def __init__(self, name: str = ...) -> None: ...
343 def frombuf(cls, buf: bytes, encoding: str, errors: str) -> TarInfo: ...
345 def fromtarfile(cls, tarfile: TarFile) -> TarInfo: ...
347 def linkpath(self) -> str: ...
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
355 def create_gnu_header(
356 self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str
358 def create_pax_header(self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str) -> bytes: ...
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: ...