summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-04-21 08:46:39 (GMT)
committerGitHub <noreply@github.com>2024-04-21 08:46:39 (GMT)
commit51ef89cd9acbfbfa7fd8d82f0c6baa388bb650c9 (patch)
treeeb6f52baa37360fb86c7401d12c47f51ad3795af /Lib/zipfile
parentccda73828473576c57d1bb31774f56542d6e8964 (diff)
downloadcpython-51ef89cd9acbfbfa7fd8d82f0c6baa388bb650c9.zip
cpython-51ef89cd9acbfbfa7fd8d82f0c6baa388bb650c9.tar.gz
cpython-51ef89cd9acbfbfa7fd8d82f0c6baa388bb650c9.tar.bz2
gh-115961: Add name and mode attributes for compressed file-like objects (GH-116036)
* Add name and mode attributes for compressed and archived file-like objects in modules bz2, lzma, tarfile and zipfile. * Change the value of the mode attribute of GzipFile from integer (1 or 2) to string ('rb' or 'wb'). * Change the value of the mode attribute of ZipExtFile from 'r' to 'rb'.
Diffstat (limited to 'Lib/zipfile')
-rw-r--r--Lib/zipfile/__init__.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py
index e4603b5..31ef9bb 100644
--- a/Lib/zipfile/__init__.py
+++ b/Lib/zipfile/__init__.py
@@ -940,7 +940,7 @@ class ZipExtFile(io.BufferedIOBase):
result = ['<%s.%s' % (self.__class__.__module__,
self.__class__.__qualname__)]
if not self.closed:
- result.append(' name=%r mode=%r' % (self.name, self.mode))
+ result.append(' name=%r' % (self.name,))
if self._compress_type != ZIP_STORED:
result.append(' compress_type=%s' %
compressor_names.get(self._compress_type,
@@ -1217,6 +1217,14 @@ class _ZipWriteFile(io.BufferedIOBase):
def _fileobj(self):
return self._zipfile.fp
+ @property
+ def name(self):
+ return self._zinfo.filename
+
+ @property
+ def mode(self):
+ return 'wb'
+
def writable(self):
return True
@@ -1687,7 +1695,7 @@ class ZipFile:
else:
pwd = None
- return ZipExtFile(zef_file, mode, zinfo, pwd, True)
+ return ZipExtFile(zef_file, mode + 'b', zinfo, pwd, True)
except:
zef_file.close()
raise