Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(25)

Unified Diff: Lib/zipfile.py

Issue 22217: Reprs for zipfile classes
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_zipfile.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/zipfile.py Tue Aug 19 18:20:48 2014 +0300
+++ b/Lib/zipfile.py Thu Aug 21 09:47:10 2014 +0300
@@ -355,6 +355,28 @@
# 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),))
berkerpeksag 2014/10/01 01:40:47 Passing a tuple is not necessary here. ' file
storchaka 2014/10/08 19:42:09 I were too paranoid here. When right argument of t
+ if lo:
+ result.append(' external_attr=%#x' % (lo,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ isdir = self.filename[-1:] == '/'
+ if not isdir or self.file_size:
+ result.append(' file_size=%r' % (self.file_size,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ 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,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ 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 @@
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),))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ 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 @@
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,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ elif self.filename is not None:
+ result.append(' filename=%r' % (self.filename,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ result.append(' mode=%r' % (self.mode,))
berkerpeksag 2014/10/01 01:40:47 Same as above.
+ 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
« no previous file with comments | « Lib/test/test_zipfile.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+