From: <zy...@us...> - 2009-01-17 18:31:10
|
Revision: 5938 http://jython.svn.sourceforge.net/jython/?rev=5938&view=rev Author: zyasoft Date: 2009-01-17 18:31:06 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Fixes #1217 where we report the underlying Java error (java.util.zip.DataFormatException) instead of the standard Python one (zlib.error). This also helps support PyAMF on Jython. Thanks Nick Joyce for the patch. Modified Paths: -------------- trunk/jython/Lib/test/test_zlib.py trunk/jython/Lib/zlib.py Modified: trunk/jython/Lib/test/test_zlib.py =================================================================== --- trunk/jython/Lib/test/test_zlib.py 2009-01-17 18:12:57 UTC (rev 5937) +++ trunk/jython/Lib/test/test_zlib.py 2009-01-17 18:31:06 UTC (rev 5938) @@ -81,6 +81,8 @@ self.assertRaises(ValueError, zlib.decompressobj().flush, 0) self.assertRaises(ValueError, zlib.decompressobj().flush, -1) + def test_decompress_badinput(self): + self.assertRaises(zlib.error, zlib.decompress, 'foo') class CompressTestCase(unittest.TestCase): Modified: trunk/jython/Lib/zlib.py =================================================================== --- trunk/jython/Lib/zlib.py 2009-01-17 18:12:57 UTC (rev 5937) +++ trunk/jython/Lib/zlib.py 2009-01-17 18:31:06 UTC (rev 5938) @@ -15,7 +15,7 @@ """ import jarray, binascii -from java.util.zip import Adler32, Deflater, Inflater +from java.util.zip import Adler32, Deflater, Inflater, DataFormatException from java.lang import Long, String from cStringIO import StringIO @@ -66,8 +66,8 @@ def decompress(string, wbits=0, bufsize=16384): inflater = Inflater(wbits < 0) inflater.setInput(string) + return _get_inflate_data(inflater) - class compressobj: # all jython uses wbits for is deciding whether to skip the header if it's negative @@ -152,22 +152,26 @@ s = StringIO() while not deflater.finished(): l = deflater.deflate(buf) + if l == 0: break s.write(String(buf, 0, 0, l)) s.seek(0) return s.read() - def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') s = StringIO() total = 0 while not inflater.finished(): - if max_length: - l = inflater.inflate(buf, 0, min(1024, max_length - total)) - else: - l = inflater.inflate(buf) + try: + if max_length: + l = inflater.inflate(buf, 0, min(1024, max_length - total)) + else: + l = inflater.inflate(buf) + except DataFormatException, e: + raise error(str(e)) + if l == 0: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |