summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-29 20:42:06 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-29 20:42:06 (GMT)
commit51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e (patch)
tree0384ead9fd97245a4b3bde37757a1fef5a405a2c /Lib/zipfile.py
parent659dd625b4c3489fbefe9fa866d87bc2b5e14366 (diff)
downloadcpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.zip
cpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.tar.gz
cpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.tar.bz2
Issue #22217: Implemented reprs of classes in the zipfile module.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index bda6134..74e1566 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -355,6 +355,28 @@ class ZipInfo (object):
# compress_size Size of the compressed file
# file_size Size of the uncompressed file
+ def __repr__(self):
+ result = ['<%s filename=%r' % (self.__class__.__name__, self.filename)]
+ if self.compress_type != ZIP_STORED:
+ result.append(' compress_type=%s' %
+ compressor_names.get(self.compress_type,
+ self.compress_type))
+ hi = self.external_attr >> 16
+ lo = self.external_attr & 0xFFFF
+ if hi:
+ result.append(' filemode=%r' % stat.filemode(hi))
+ if lo:
+ result.append(' external_attr=%#x' % lo)
+ isdir = self.filename[-1:] == '/'
+ if not isdir or self.file_size:
+ result.append(' file_size=%r' % self.file_size)
+ if ((not isdir or self.compress_size) and
+ (self.compress_type != ZIP_STORED or
+ self.file_size != self.compress_size)):
+ result.append(' compress_size=%r' % self.compress_size)
+ result.append('>')
+ return ''.join(result)
+
def FileHeader(self, zip64=None):
"""Return the per-file header as a string."""
dt = self.date_time
@@ -671,6 +693,20 @@ class ZipExtFile(io.BufferedIOBase):
else:
self._expected_crc = None
+ def __repr__(self):
+ result = ['<%s.%s' % (self.__class__.__module__,
+ self.__class__.__qualname__)]
+ if not self.closed:
+ result.append(' name=%r mode=%r' % (self.name, self.mode))
+ if self._compress_type != ZIP_STORED:
+ result.append(' compress_type=%s' %
+ compressor_names.get(self._compress_type,
+ self._compress_type))
+ else:
+ result.append(' [closed]')
+ result.append('>')
+ return ''.join(result)
+
def readline(self, limit=-1):
"""Read and return a line from the stream.
@@ -967,6 +1003,20 @@ class ZipFile:
def __exit__(self, type, value, traceback):
self.close()
+ def __repr__(self):
+ result = ['<%s.%s' % (self.__class__.__module__,
+ self.__class__.__qualname__)]
+ if self.fp is not None:
+ if self._filePassed:
+ result.append(' file=%r' % self.fp)
+ elif self.filename is not None:
+ result.append(' filename=%r' % self.filename)
+ result.append(' mode=%r' % self.mode)
+ else:
+ result.append(' [closed]')
+ result.append('>')
+ return ''.join(result)
+
def _RealGetContents(self):
"""Read in the table of contents for the ZIP file."""
fp = self.fp