[pypy-commit] pypy py3.3: Fix zlib's test_decompress_eof.
Valentina Mukhamedzhanova
noreply at buildbot.pypy.org
Sat Jul 26 14:52:48 CEST 2014
Author: Valentina Mukhamedzhanova <umirra at gmail.com>
Branch: py3.3
Changeset: r72504:c22750fbe7ad
Date: 2014-07-26 14:46 +0200
http://bitbucket.org/pypy/pypy/changeset/c22750fbe7ad/
Log: Fix zlib's test_decompress_eof.
diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -1,7 +1,7 @@
import sys
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, interp_attrproperty_bytes
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty_bytes, interp_attrproperty
from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib.rarithmetic import intmask, r_uint
from rpython.rlib.objectmodel import keepalive_until_here
@@ -231,6 +231,7 @@
ZLibObject.__init__(self, space)
self.unused_data = ''
self.unconsumed_tail = ''
+ self.eof = False
try:
self.stream = rzlib.inflateInit(wbits)
except rzlib.RZlibError, e:
@@ -238,7 +239,7 @@
except ValueError:
raise OperationError(space.w_ValueError,
space.wrap("Invalid initialization option"))
-
+
def __del__(self):
"""Automatically free the resources used by the stream."""
if self.stream:
@@ -280,6 +281,7 @@
raise zlib_error(space, e.msg)
string, finished, unused_len = result
+ self.eof = finished
self._save_unconsumed_input(data, finished, unused_len)
return space.wrapbytes(string)
@@ -327,6 +329,7 @@
flush = interp2app(Decompress.flush),
unused_data = interp_attrproperty_bytes('unused_data', Decompress),
unconsumed_tail = interp_attrproperty_bytes('unconsumed_tail', Decompress),
+ eof = interp_attrproperty('eof', Decompress),
__doc__ = """decompressobj([wbits]) -- Return a decompressor object.
Optional arg wbits is the window buffer size.
diff --git a/pypy/module/zlib/test/test_zlib.py b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -166,6 +166,18 @@
dco = zlib.decompressobj()
assert dco.flush() == b""
+ def test_decompress_eof(self):
+ import zlib
+ x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E' # 'foo'
+ dco = zlib.decompressobj()
+ assert dco.eof == False
+ dco.decompress(x[:-5])
+ assert dco.eof == False
+ dco.decompress(x[-5:])
+ assert dco.eof == True
+ dco.flush()
+ assert dco.eof == True
+
def test_decompress_incomplete_stream(self):
import zlib
# This is 'foo', deflated
More information about the pypy-commit
mailing list