diff options
author | Philip Jenvey <pjenvey@underboss.org> | 2014-03-12 15:34:53 -0700 |
---|---|---|
committer | Philip Jenvey <pjenvey@underboss.org> | 2014-03-12 15:34:53 -0700 |
commit | c3eaff855671da6eb73ff0a46e346c7dd1107827 (patch) | |
tree | 6d3834bce63014d64af7de32707b77199d1d8dec /lib-python/3/gzip.py | |
parent | update python 2 stdlib to 2.7.6 (diff) | |
download | pypy-c3eaff855671da6eb73ff0a46e346c7dd1107827.tar.gz pypy-c3eaff855671da6eb73ff0a46e346c7dd1107827.tar.bz2 pypy-c3eaff855671da6eb73ff0a46e346c7dd1107827.zip |
update the Python 3 stdlib to v3.2.5
Diffstat (limited to 'lib-python/3/gzip.py')
-rw-r--r-- | lib-python/3/gzip.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib-python/3/gzip.py b/lib-python/3/gzip.py index 1de23b6972..6aacc9a4f9 100644 --- a/lib-python/3/gzip.py +++ b/lib-python/3/gzip.py @@ -137,9 +137,10 @@ class GzipFile(io.BufferedIOBase): A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and 'wb', and 'a' and 'ab'. - The compresslevel argument is an integer from 1 to 9 controlling the + The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, - and 9 is slowest and produces the most compression. The default is 9. + and 9 is slowest and produces the most compression. 0 is no compression + at all. The default is 9. The mtime argument is an optional numeric timestamp to be written to the stream when compressing. All gzip compressed streams @@ -159,9 +160,8 @@ class GzipFile(io.BufferedIOBase): if fileobj is None: fileobj = self.myfileobj = builtins.open(filename, mode or 'rb') if filename is None: - if hasattr(fileobj, 'name') and isinstance(fileobj.name, str): - filename = fileobj.name - else: + filename = getattr(fileobj, 'name', '') + if not isinstance(filename, (str, bytes)): filename = '' if mode is None: if hasattr(fileobj, 'mode'): mode = fileobj.mode @@ -236,7 +236,8 @@ class GzipFile(io.BufferedIOBase): # RFC 1952 requires the FNAME field to be Latin-1. Do not # include filenames that cannot be represented that way. fname = os.path.basename(self.name) - fname = fname.encode('latin-1') + if not isinstance(fname, bytes): + fname = fname.encode('latin-1') if fname.endswith(b'.gz'): fname = fname[:-3] except UnicodeEncodeError: @@ -366,8 +367,10 @@ class GzipFile(io.BufferedIOBase): if self.fileobj is None: return b'' try: - # 1024 is the same buffering heuristic used in read() - self._read(max(n, 1024)) + # Ensure that we don't return b"" if we haven't reached EOF. + while self.extrasize == 0: + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) except EOFError: pass offset = self.offset - self.extrastart @@ -573,7 +576,7 @@ class GzipFile(io.BufferedIOBase): def compress(data, compresslevel=9): """Compress data in one shot and return the compressed string. - Optional argument is the compression level, in range of 1-9. + Optional argument is the compression level, in range of 0-9. """ buf = io.BytesIO() with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f: @@ -621,9 +624,9 @@ def _test(): if not chunk: break g.write(chunk) - if g is not sys.stdout: + if g is not sys.stdout.buffer: g.close() - if f is not sys.stdin: + if f is not sys.stdin.buffer: f.close() if __name__ == '__main__': |