diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/tarfile.py | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/tarfile.py')
| -rw-r--r-- | contrib/tools/python3/src/Lib/tarfile.py | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/contrib/tools/python3/src/Lib/tarfile.py b/contrib/tools/python3/src/Lib/tarfile.py index d832e1c5fc2..043a4ab5a52 100644 --- a/contrib/tools/python3/src/Lib/tarfile.py +++ b/contrib/tools/python3/src/Lib/tarfile.py @@ -105,7 +105,7 @@ SOLARIS_XHDTYPE = b"X" # Solaris extended header USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format GNU_FORMAT = 1 # GNU tar format PAX_FORMAT = 2 # POSIX.1-2001 (pax) format -DEFAULT_FORMAT = PAX_FORMAT +DEFAULT_FORMAT = PAX_FORMAT #--------------------------------------------------------- # tarfile constants @@ -420,8 +420,8 @@ class _Stream: self.__write(b"\037\213\010\010" + timestamp + b"\002\377") if self.name.endswith(".gz"): self.name = self.name[:-3] - # Honor "directory components removed" from RFC1952 - self.name = os.path.basename(self.name) + # Honor "directory components removed" from RFC1952 + self.name = os.path.basename(self.name) # RFC1952 says we must use ISO-8859-1 for the FNAME field. self.__write(self.name.encode("iso-8859-1", "replace") + NUL) @@ -515,10 +515,10 @@ class _Stream: raise StreamError("seeking backwards is not allowed") return self.pos - def read(self, size): - """Return the next size number of bytes from the stream.""" - assert size is not None - buf = self._read(size) + def read(self, size): + """Return the next size number of bytes from the stream.""" + assert size is not None + buf = self._read(size) self.pos += len(buf) return buf @@ -531,14 +531,14 @@ class _Stream: c = len(self.dbuf) t = [self.dbuf] while c < size: - # Skip underlying buffer to avoid unaligned double buffering. - if self.buf: - buf = self.buf - self.buf = b"" - else: - buf = self.fileobj.read(self.bufsize) - if not buf: - break + # Skip underlying buffer to avoid unaligned double buffering. + if self.buf: + buf = self.buf + self.buf = b"" + else: + buf = self.fileobj.read(self.bufsize) + if not buf: + break try: buf = self.cmp.decompress(buf) except self.exception: @@ -719,32 +719,32 @@ class TarInfo(object): usually created internally. """ - __slots__ = dict( - name = 'Name of the archive member.', - mode = 'Permission bits.', - uid = 'User ID of the user who originally stored this member.', - gid = 'Group ID of the user who originally stored this member.', - size = 'Size in bytes.', - mtime = 'Time of last modification.', - chksum = 'Header checksum.', - type = ('File type. type is usually one of these constants: ' - 'REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, ' - 'CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.'), - linkname = ('Name of the target file name, which is only present ' - 'in TarInfo objects of type LNKTYPE and SYMTYPE.'), - uname = 'User name.', - gname = 'Group name.', - devmajor = 'Device major number.', - devminor = 'Device minor number.', - offset = 'The tar header starts here.', - offset_data = "The file's data starts here.", - pax_headers = ('A dictionary containing key-value pairs of an ' - 'associated pax extended header.'), - sparse = 'Sparse member information.', - tarfile = None, - _sparse_structs = None, - _link_target = None, - ) + __slots__ = dict( + name = 'Name of the archive member.', + mode = 'Permission bits.', + uid = 'User ID of the user who originally stored this member.', + gid = 'Group ID of the user who originally stored this member.', + size = 'Size in bytes.', + mtime = 'Time of last modification.', + chksum = 'Header checksum.', + type = ('File type. type is usually one of these constants: ' + 'REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, ' + 'CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.'), + linkname = ('Name of the target file name, which is only present ' + 'in TarInfo objects of type LNKTYPE and SYMTYPE.'), + uname = 'User name.', + gname = 'Group name.', + devmajor = 'Device major number.', + devminor = 'Device minor number.', + offset = 'The tar header starts here.', + offset_data = "The file's data starts here.", + pax_headers = ('A dictionary containing key-value pairs of an ' + 'associated pax extended header.'), + sparse = 'Sparse member information.', + tarfile = None, + _sparse_structs = None, + _link_target = None, + ) def __init__(self, name=""): """Construct a TarInfo object. name is the optional name @@ -772,7 +772,7 @@ class TarInfo(object): @property def path(self): - 'In pax headers, "name" is called "path".' + 'In pax headers, "name" is called "path".' return self.name @path.setter @@ -781,7 +781,7 @@ class TarInfo(object): @property def linkpath(self): - 'In pax headers, "linkname" is called "linkpath".' + 'In pax headers, "linkname" is called "linkpath".' return self.linkname @linkpath.setter @@ -932,14 +932,14 @@ class TarInfo(object): """Return a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. """ - has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE) - if has_device_fields: - devmajor = itn(info.get("devmajor", 0), 8, format) - devminor = itn(info.get("devminor", 0), 8, format) - else: - devmajor = stn("", 8, encoding, errors) - devminor = stn("", 8, encoding, errors) - + has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE) + if has_device_fields: + devmajor = itn(info.get("devmajor", 0), 8, format) + devminor = itn(info.get("devminor", 0), 8, format) + else: + devmajor = stn("", 8, encoding, errors) + devminor = stn("", 8, encoding, errors) + parts = [ stn(info.get("name", ""), 100, encoding, errors), itn(info.get("mode", 0) & 0o7777, 8, format), @@ -953,8 +953,8 @@ class TarInfo(object): info.get("magic", POSIX_MAGIC), stn(info.get("uname", ""), 32, encoding, errors), stn(info.get("gname", ""), 32, encoding, errors), - devmajor, - devminor, + devmajor, + devminor, stn(info.get("prefix", ""), 155, encoding, errors) ] @@ -1251,8 +1251,8 @@ class TarInfo(object): length, keyword = match.groups() length = int(length) - if length == 0: - raise InvalidHeaderError("invalid header") + if length == 0: + raise InvalidHeaderError("invalid header") value = buf[match.end(2) + 1:match.start(1) + length - 1] # Normally, we could just use "utf-8" as the encoding and "strict" @@ -1383,42 +1383,42 @@ class TarInfo(object): return blocks * BLOCKSIZE def isreg(self): - 'Return True if the Tarinfo object is a regular file.' + 'Return True if the Tarinfo object is a regular file.' return self.type in REGULAR_TYPES - + def isfile(self): - 'Return True if the Tarinfo object is a regular file.' + 'Return True if the Tarinfo object is a regular file.' return self.isreg() - + def isdir(self): - 'Return True if it is a directory.' + 'Return True if it is a directory.' return self.type == DIRTYPE - + def issym(self): - 'Return True if it is a symbolic link.' + 'Return True if it is a symbolic link.' return self.type == SYMTYPE - + def islnk(self): - 'Return True if it is a hard link.' + 'Return True if it is a hard link.' return self.type == LNKTYPE - + def ischr(self): - 'Return True if it is a character device.' + 'Return True if it is a character device.' return self.type == CHRTYPE - + def isblk(self): - 'Return True if it is a block device.' + 'Return True if it is a block device.' return self.type == BLKTYPE - + def isfifo(self): - 'Return True if it is a FIFO.' + 'Return True if it is a FIFO.' return self.type == FIFOTYPE - + def issparse(self): return self.sparse is not None - + def isdev(self): - 'Return True if it is one of character device, block device or FIFO.' + 'Return True if it is one of character device, block device or FIFO.' return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE) # class TarInfo @@ -1667,12 +1667,12 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - from gzip import GzipFile - except ImportError: + from gzip import GzipFile + except ImportError: raise CompressionError("gzip module is not available") try: - fileobj = GzipFile(name, mode + "b", compresslevel, fileobj) + fileobj = GzipFile(name, mode + "b", compresslevel, fileobj) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") @@ -1700,11 +1700,11 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - from bz2 import BZ2File + from bz2 import BZ2File except ImportError: raise CompressionError("bz2 module is not available") - fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel) + fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel) try: t = cls.taropen(name, mode, fileobj, **kwargs) @@ -1728,15 +1728,15 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - from lzma import LZMAFile, LZMAError + from lzma import LZMAFile, LZMAError except ImportError: raise CompressionError("lzma module is not available") - fileobj = LZMAFile(fileobj or name, mode, preset=preset) + fileobj = LZMAFile(fileobj or name, mode, preset=preset) try: t = cls.taropen(name, mode, fileobj, **kwargs) - except (LZMAError, EOFError): + except (LZMAError, EOFError): fileobj.close() if mode == 'r': raise ReadError("not an lzma file") @@ -1836,9 +1836,9 @@ class TarFile(object): tarinfo = self.tarinfo() tarinfo.tarfile = self # Not needed - # Use os.stat or os.lstat, depending on if symlinks shall be resolved. + # Use os.stat or os.lstat, depending on if symlinks shall be resolved. if fileobj is None: - if not self.dereference: + if not self.dereference: statres = os.lstat(name) else: statres = os.stat(name) @@ -2093,10 +2093,10 @@ class TarFile(object): def extractfile(self, member): """Extract a member from the archive as a file object. `member' may be - a filename or a TarInfo object. If `member' is a regular file or - a link, an io.BufferedReader object is returned. For all other - existing members, None is returned. If `member' does not appear - in the archive, KeyError is raised. + a filename or a TarInfo object. If `member' is a regular file or + a link, an io.BufferedReader object is returned. For all other + existing members, None is returned. If `member' does not appear + in the archive, KeyError is raised. """ self._check("r") @@ -2237,9 +2237,9 @@ class TarFile(object): try: # For systems that support symbolic and hard links. if tarinfo.issym(): - if os.path.lexists(targetpath): - # Avoid FileExistsError on following os.symlink. - os.unlink(targetpath) + if os.path.lexists(targetpath): + # Avoid FileExistsError on following os.symlink. + os.unlink(targetpath) os.symlink(tarinfo.linkname, targetpath) else: # See extract(). @@ -2287,10 +2287,10 @@ class TarFile(object): def chmod(self, tarinfo, targetpath): """Set file permissions of targetpath according to tarinfo. """ - try: - os.chmod(targetpath, tarinfo.mode) - except OSError: - raise ExtractError("could not change mode") + try: + os.chmod(targetpath, tarinfo.mode) + except OSError: + raise ExtractError("could not change mode") def utime(self, tarinfo, targetpath): """Set modification time of targetpath according to tarinfo. @@ -2345,15 +2345,15 @@ class TarFile(object): raise ReadError(str(e)) except SubsequentHeaderError as e: raise ReadError(str(e)) - except Exception as e: - try: - import zlib - if isinstance(e, zlib.error): - raise ReadError(f'zlib error: {e}') - else: - raise e - except ImportError: - raise e + except Exception as e: + try: + import zlib + if isinstance(e, zlib.error): + raise ReadError(f'zlib error: {e}') + else: + raise e + except ImportError: + raise e break if tarinfo is not None: @@ -2484,14 +2484,14 @@ class TarFile(object): def is_tarfile(name): """Return True if name points to a tar archive that we are able to handle, else return False. - - 'name' should be a string, file, or file-like object. + + 'name' should be a string, file, or file-like object. """ try: - if hasattr(name, "read"): - t = open(fileobj=name) - else: - t = open(name) + if hasattr(name, "read"): + t = open(fileobj=name) + else: + t = open(name) t.close() return True except TarError: |
