summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-13 14:37:26 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-13 14:37:26 (GMT)
commit8e33fd78c4db7b250995652510067d7f3a8117cd (patch)
tree2aca383967f6dcca3ef0785ebe1ed6899a4821bf
parentf068f94e82aaab9789c8b1065ec5f7fb94fa70ad (diff)
downloadcpython-8e33fd78c4db7b250995652510067d7f3a8117cd.zip
cpython-8e33fd78c4db7b250995652510067d7f3a8117cd.tar.gz
cpython-8e33fd78c4db7b250995652510067d7f3a8117cd.tar.bz2
Merged revisions 77472-77473 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77472 | antoine.pitrou | 2010-01-13 15:32:10 +0100 (mer., 13 janv. 2010) | 5 lines Issue #2846: Add support for gzip.GzipFile reading zero-padded files. Patch by Brian Curtin. ........ r77473 | antoine.pitrou | 2010-01-13 15:32:51 +0100 (mer., 13 janv. 2010) | 3 lines Add ACKS entry for r77472. ........
-rw-r--r--Doc/library/gzip.rst3
-rw-r--r--Lib/gzip.py9
-rw-r--r--Lib/test/test_gzip.py12
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
5 files changed, 28 insertions, 0 deletions
diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst
index 1f64428..a830593 100644
--- a/Doc/library/gzip.rst
+++ b/Doc/library/gzip.rst
@@ -72,6 +72,9 @@ The module defines the following items:
.. versionchanged:: 3.1
Support for the :keyword:`with` statement was added.
+ .. versionchanged:: 3.2
+ Support for zero-padded files was added.
+
.. function:: open(filename, mode='rb', compresslevel=9)
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 66fc88d..ef6befc 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -348,6 +348,15 @@ class GzipFile(io.BufferedIOBase):
elif isize != (self.size & 0xffffffff):
raise IOError("Incorrect length of data produced")
+ # Gzip files can be padded with zeroes and still have archives.
+ # Consume all zero bytes and set the file position to the first
+ # non-zero byte. See http://www.gzip.org/#faq8
+ c = b"\x00"
+ while c == b"\x00":
+ c = self.fileobj.read(1)
+ if c:
+ self.fileobj.seek(-1, 1)
+
@property
def closed(self):
return self.fileobj is None
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 320adfd..429ada0 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -253,6 +253,18 @@ class TestGzip(unittest.TestCase):
else:
self.fail("1/0 didn't raise an exception")
+ def test_zero_padded_file(self):
+ with gzip.GzipFile(self.filename, "wb") as f:
+ f.write(data1 * 50)
+
+ # Pad the file with zeroes
+ with open(self.filename, "ab") as f:
+ f.write(b"\x00" * 50)
+
+ with gzip.GzipFile(self.filename, "rb") as f:
+ d = f.read()
+ self.assertEqual(d, data1 * 50, "Incorrect data in file")
+
def test_main(verbose=None):
support.run_unittest(TestGzip)
diff --git a/Misc/ACKS b/Misc/ACKS
index 72e2096..f0c667a 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -164,6 +164,7 @@ Simon Cross
Drew Csillag
John Cugini
Tom Culliton
+Brian Curtin
Lisandro Dalcin
Andrew Dalke
Lars Damerow
diff --git a/Misc/NEWS b/Misc/NEWS
index 3e4073d..a577e65 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -213,6 +213,9 @@ C-API
Library
-------
+- Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
+ Patch by Brian Curtin.
+
- Issue #7681: Use floor division in appropiate places in the wave module.
- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since