[Python-checkins] r77472 - in python/trunk: Doc/library/gzip.rst Lib/gzip.py Lib/test/test_gzip.py Misc/NEWS
antoine.pitrou
python-checkins at python.org
Wed Jan 13 15:32:11 CET 2010
Author: antoine.pitrou
Date: Wed Jan 13 15:32:10 2010
New Revision: 77472
Log:
Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
Patch by Brian Curtin.
Modified:
python/trunk/Doc/library/gzip.rst
python/trunk/Lib/gzip.py
python/trunk/Lib/test/test_gzip.py
python/trunk/Misc/NEWS
Modified: python/trunk/Doc/library/gzip.rst
==============================================================================
--- python/trunk/Doc/library/gzip.rst (original)
+++ python/trunk/Doc/library/gzip.rst Wed Jan 13 15:32:10 2010
@@ -72,6 +72,9 @@
.. versionchanged:: 2.7
Support for the :keyword:`with` statement was added.
+ .. versionchanged:: 2.7
+ Support for zero-padded files was added.
+
.. function:: open(filename[, mode[, compresslevel]])
Modified: python/trunk/Lib/gzip.py
==============================================================================
--- python/trunk/Lib/gzip.py (original)
+++ python/trunk/Lib/gzip.py Wed Jan 13 15:32:10 2010
@@ -330,6 +330,15 @@
elif isize != (self.size & 0xffffffffL):
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 = "\x00"
+ while c == "\x00":
+ c = self.fileobj.read(1)
+ if c:
+ self.fileobj.seek(-1, 1)
+
@property
def closed(self):
return self.fileobj is None
Modified: python/trunk/Lib/test/test_gzip.py
==============================================================================
--- python/trunk/Lib/test/test_gzip.py (original)
+++ python/trunk/Lib/test/test_gzip.py Wed Jan 13 15:32:10 2010
@@ -252,6 +252,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("\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):
test_support.run_unittest(TestGzip)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Wed Jan 13 15:32:10 2010
@@ -32,6 +32,9 @@
Library
-------
+- Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
+ Patch by Brian Curtin.
+
- Issue #5827: Make sure that normpath preserves unicode. Initial patch
by Matt Giuca.
More information about the Python-checkins
mailing list