From f52b154fe7b5d2bc7dda0b8887721d0fb8c77be0 Mon Sep 17 00:00:00 2001 From: Ankur Singh <71101202+asing1@users.noreply.github.com> Date: Tue, 16 Feb 2021 03:49:49 +0530 Subject: [PATCH] Add missing definitions in tarfile (#5020) Resolves #4885 --- stdlib/tarfile.pyi | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 12e80480c..5357b087a 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -1,3 +1,4 @@ +import io import sys from _typeshed import AnyPath, StrPath from types import TracebackType @@ -72,7 +73,11 @@ def open( compresslevel: Optional[int] = ..., ) -> TarFile: ... +class ExFileObject(io.BufferedReader): + def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ... + class TarFile(Iterable[TarInfo]): + OPEN_METH: Mapping[str, str] name: Optional[AnyPath] mode: str fileobj: Optional[IO[bytes]] @@ -82,6 +87,7 @@ class TarFile(Iterable[TarInfo]): ignore_zeros: Optional[bool] encoding: Optional[str] errors: str + fileobject: Type[ExFileObject] pax_headers: Optional[Mapping[str, str]] debug: Optional[int] errorlevel: Optional[int] @@ -126,6 +132,74 @@ class TarFile(Iterable[TarInfo]): debug: Optional[int] = ..., errorlevel: Optional[int] = ..., ) -> TarFile: ... + @classmethod + def taropen( + cls, + name: AnyPath, + mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., + *, + compresslevel: int = ..., + format: Optional[int] = ..., + tarinfo: Optional[Type[TarInfo]] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + ) -> TarFile: ... + @classmethod + def gzopen( + cls, + name: AnyPath, + mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., + compresslevel: int = ..., + *, + format: Optional[int] = ..., + tarinfo: Optional[Type[TarInfo]] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + ) -> TarFile: ... + @classmethod + def bz2open( + cls, + name: AnyPath, + mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., + compresslevel: int = ..., + *, + format: Optional[int] = ..., + tarinfo: Optional[Type[TarInfo]] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + ) -> TarFile: ... + @classmethod + def xzopen( + cls, + name: AnyPath, + mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., + preset: Optional[int] = ..., + *, + format: Optional[int] = ..., + tarinfo: Optional[Type[TarInfo]] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + ) -> TarFile: ... def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> List[TarInfo]: ... def getnames(self) -> List[str]: ... @@ -218,6 +292,13 @@ class TarInfo: path: str size: int mtime: int + chksum: int + devmajor: int + devminor: int + offset: int + offset_data: int + sparse: Optional[bytes] + tarfile: Optional[TarFile] mode: int type: bytes linkname: str @@ -235,9 +316,20 @@ class TarInfo: def frombuf(cls, buf: bytes) -> TarInfo: ... @classmethod def fromtarfile(cls, tarfile: TarFile) -> TarInfo: ... + @property + def linkpath(self) -> str: ... + @linkpath.setter + def linkpath(self, linkname: str) -> None: ... + def get_info(self) -> Mapping[str, Union[str, int, bytes, Mapping[str, str]]]: ... def tobuf(self, format: Optional[int] = ..., encoding: Optional[str] = ..., errors: str = ...) -> bytes: ... + def create_ustar_header(self, info: Mapping[str, Union[str, int, bytes, Mapping[str, str]]], encoding: str, errors: str): ... + def create_gnu_header(self, info: Mapping[str, Union[str, int, bytes, Mapping[str, str]]], encoding: str, errors: str): ... + def create_pax_header(self, info: Mapping[str, Union[str, int, bytes, Mapping[str, str]]], encoding: str): ... + @classmethod + def create_pax_global_header(cls, pax_headers: Mapping[str, str]) -> bytes: ... def isfile(self) -> bool: ... def isreg(self) -> bool: ... + def issparse(self) -> bool: ... def isdir(self) -> bool: ... def issym(self) -> bool: ... def islnk(self) -> bool: ...