[Python-checkins] r77474 - in python/branches/py3k: Doc/library/gzip.rst Lib/gzip.py Lib/test/test_gzip.py Misc/ACKS Misc/NEWS
antoine.pitrou
python-checkins at python.org
Wed Jan 13 15:37:27 CET 2010
Author: antoine.pitrou
Date: Wed Jan 13 15:37:26 2010
New Revision: 77474
Log:
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.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/library/gzip.rst
python/branches/py3k/Lib/gzip.py
python/branches/py3k/Lib/test/test_gzip.py
python/branches/py3k/Misc/ACKS
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Doc/library/gzip.rst
==============================================================================
--- python/branches/py3k/Doc/library/gzip.rst (original)
+++ python/branches/py3k/Doc/library/gzip.rst Wed Jan 13 15:37:26 2010
@@ -72,6 +72,9 @@
.. 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)
Modified: python/branches/py3k/Lib/gzip.py
==============================================================================
--- python/branches/py3k/Lib/gzip.py (original)
+++ python/branches/py3k/Lib/gzip.py Wed Jan 13 15:37:26 2010
@@ -348,6 +348,15 @@
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
Modified: python/branches/py3k/Lib/test/test_gzip.py
==============================================================================
--- python/branches/py3k/Lib/test/test_gzip.py (original)
+++ python/branches/py3k/Lib/test/test_gzip.py Wed Jan 13 15:37:26 2010
@@ -253,6 +253,18 @@
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)
Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS (original)
+++ python/branches/py3k/Misc/ACKS Wed Jan 13 15:37:26 2010
@@ -164,6 +164,7 @@
Drew Csillag
John Cugini
Tom Culliton
+Brian Curtin
Lisandro Dalcin
Andrew Dalke
Lars Damerow
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Wed Jan 13 15:37:26 2010
@@ -213,6 +213,9 @@
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
More information about the Python-checkins
mailing list