Rev 5394: (gz) Adapt tuned_gzip to changes to gzip module crc handling in Python 2.7 in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sun Aug 29 23:14:46 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5394 [merge]
revision-id: pqm at pqm.ubuntu.com-20100829221442-f5573xyzlm7gr7t6
parent: pqm at pqm.ubuntu.com-20100827220935-gwk3320p99ggl80n
parent: gzlist at googlemail.com-20100829183045-cs8btrfnw1yvc9pt
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2010-08-29 23:14:42 +0100
message:
  (gz) Adapt tuned_gzip to changes to gzip module crc handling in Python 2.7
   (Martin [gz])
modified:
  bzrlib/tests/test_tuned_gzip.py test_tuned_gzip.py-20060418042056-c576dfc708984968
  bzrlib/tuned_gzip.py           tuned_gzip.py-20060407014720-5aadc518e928e8d2
=== modified file 'bzrlib/tests/test_tuned_gzip.py'
--- a/bzrlib/tests/test_tuned_gzip.py	2009-06-02 19:56:24 +0000
+++ b/bzrlib/tests/test_tuned_gzip.py	2010-08-29 18:29:22 +0000
@@ -86,6 +86,15 @@
         # and it should be new member time in the stream.
         self.failUnless(myfile._new_member)
 
+    def test_negative_crc(self):
+        """Content with a negative crc should not break when written"""
+        sio = StringIO()
+        gfile = tuned_gzip.GzipFile(mode="w", fileobj=sio)
+        gfile.write("\xFF")
+        gfile.close()
+        self.assertEqual(gfile.crc & 0xFFFFFFFFL, 0xFF000000L)
+        self.assertEqual(sio.getvalue()[-8:-4], "\x00\x00\x00\xFF")
+
 
 class TestToGzip(TestCase):
 

=== modified file 'bzrlib/tuned_gzip.py'
--- a/bzrlib/tuned_gzip.py	2009-06-02 19:56:24 +0000
+++ b/bzrlib/tuned_gzip.py	2010-08-29 18:30:45 +0000
@@ -395,4 +395,12 @@
         # (4 seconds to 1 seconds for the sample upgrades I was testing).
         self.write(''.join(lines))
 
+    if sys.version_info > (2, 7):
+        # As of Python 2.7 the crc32 must be positive when close is called
+        def close(self):
+            if self.fileobj is None:
+                return
+            if self.mode == gzip.WRITE:
+                self.crc &= 0xFFFFFFFFL
+            gzip.GzipFile.close(self)
 




More information about the bazaar-commits mailing list