[pypy-svn] pypy default: Be sure to open the zip file in binary mode,

amauryfa commits-noreply at bitbucket.org
Mon Mar 7 17:47:43 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42462:5d74d52827c9
Date: 2011-03-07 17:41 +0100
http://bitbucket.org/pypy/pypy/changeset/5d74d52827c9/

Log:	Be sure to open the zip file in binary mode, otherwise CRLF
	translation occurs and CRC is out of sync...

diff --git a/pypy/rlib/test/test_rzipfile.py b/pypy/rlib/test/test_rzipfile.py
--- a/pypy/rlib/test/test_rzipfile.py
+++ b/pypy/rlib/test/test_rzipfile.py
@@ -20,7 +20,7 @@
         cls.zipname = zipname
         zipfile = ZipFile(zipname, "w", compression=cls.compression)
         cls.year = time.localtime(time.time())[0]
-        zipfile.writestr("one", "stuff")
+        zipfile.writestr("one", "stuff\n")
         zipfile.writestr("dir" + os.path.sep + "two", "otherstuff")
         # Value selected to produce a CRC32 which is negative if
         # interpreted as a signed 32 bit integer.  This exercises the
@@ -36,7 +36,7 @@
             rzip = RZipFile(zipname, "r", compression)
             info = rzip.getinfo('one')
             return (info.date_time[0] == year and
-                    rzip.read('one') == 'stuff' and
+                    rzip.read('one') == 'stuff\n' and
                     rzip.read('three') == 'hello, world')
 
         assert one()

diff --git a/pypy/rlib/rzipfile.py b/pypy/rlib/rzipfile.py
--- a/pypy/rlib/rzipfile.py
+++ b/pypy/rlib/rzipfile.py
@@ -150,11 +150,11 @@
             raise TypeError("Read only support by now")
         self.compression = compression
         self.filename = zipname
-        self.mode = mode
         self.filelist = []
         self.NameToInfo = {}
         if 'b' not in mode:
             mode += 'b'
+        self.mode = mode
         fp = self.get_fp()
         try:
             self._GetContents(fp)
@@ -260,4 +260,4 @@
                 raise BadZipfile, "Bad CRC-32 for file %s" % filename
             return bytes
         finally:
-            fp.close()
\ No newline at end of file
+            fp.close()


More information about the Pypy-commit mailing list