[pypy-svn] r55219 - in pypy/dist/pypy/rlib: . test
fijal at codespeak.net
fijal at codespeak.net
Sun May 25 23:14:14 CEST 2008
Author: fijal
Date: Sun May 25 23:14:13 2008
New Revision: 55219
Modified:
pypy/dist/pypy/rlib/rzipfile.py
pypy/dist/pypy/rlib/test/test_rzipfile.py
Log:
A test and a fix for compression
Modified: pypy/dist/pypy/rlib/rzipfile.py
==============================================================================
--- pypy/dist/pypy/rlib/rzipfile.py (original)
+++ pypy/dist/pypy/rlib/rzipfile.py Sun May 25 23:14:13 2008
@@ -20,9 +20,6 @@
result = crc ^ 0xffffffffL
- if result > 2**31:
- result = ((result + 2**31) % r_uint(2**32)) - 2**31
-
return result
# parts copied from zipfile library implementation
@@ -146,6 +143,7 @@
if mode != 'r':
raise TypeError("Read only support by now")
self.compression = compression
+ self.filename = zipname
self.mode = mode
self.filelist = []
self.NameToInfo = {}
@@ -223,14 +221,15 @@
if zinfo.compress_type == ZIP_STORED:
pass
elif zinfo.compress_type == ZIP_DEFLATED:
- raise NotImplementedError
- # zlib compress/decompress code by Jeremy Hylton of CNRI
- dc = zlib.decompressobj(-15)
- bytes = dc.decompress(bytes)
- # need to feed in unused pad byte so that zlib won't choke
- ex = dc.decompress('Z') + dc.flush()
- if ex:
- bytes = bytes + ex
+ stream = rzlib.inflateInit(wbits=-15)
+ try:
+ bytes, _, _ = rzlib.decompress(stream, bytes)
+ # need to feed in unused pad byte so that zlib won't choke
+ ex, _, _ = rzlib.decompress(stream, 'Z')
+ if ex:
+ bytes = bytes + ex
+ finally:
+ rzlib.inflateEnd(stream)
else:
raise BadZipfile, \
"Unsupported compression method %d for file %s" % \
Modified: pypy/dist/pypy/rlib/test/test_rzipfile.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rzipfile.py (original)
+++ pypy/dist/pypy/rlib/test/test_rzipfile.py Sun May 25 23:14:13 2008
@@ -12,7 +12,7 @@
tmpdir = udir.ensure('zipimport_%s' % cls.__name__, dir=1)
zipname = str(tmpdir.join("somezip.zip"))
cls.zipname = zipname
- zipfile = ZipFile(zipname, "w")
+ zipfile = ZipFile(zipname, "w", compression=cls.compression)
cls.year = time.localtime(time.time())[0]
zipfile.writestr("one", "stuff")
zipfile.writestr("dir" + os.path.sep + "two", "otherstuff")
@@ -33,3 +33,6 @@
class TestRZipFile(BaseTestRZipFile, LLRtypeMixin):
compression = ZIP_STORED
+
+class TestRZipFileCompressed(BaseTestRZipFile, LLRtypeMixin):
+ compression = ZIP_DEFLATED
More information about the Pypy-commit
mailing list