mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #12646: Add an 'eof' attribute to zlib.Decompress.
This will make it easier to detect truncated input streams. Also, make zlib's error messages more consistent.
This commit is contained in:
parent
74b6abf61f
commit
1c38546e49
4 changed files with 48 additions and 14 deletions
|
@ -447,6 +447,26 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
|
|||
y += dco.flush()
|
||||
self.assertEqual(y, b'foo')
|
||||
|
||||
def test_decompress_eof(self):
|
||||
x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E' # 'foo'
|
||||
dco = zlib.decompressobj()
|
||||
self.assertFalse(dco.eof)
|
||||
dco.decompress(x[:-5])
|
||||
self.assertFalse(dco.eof)
|
||||
dco.decompress(x[-5:])
|
||||
self.assertTrue(dco.eof)
|
||||
dco.flush()
|
||||
self.assertTrue(dco.eof)
|
||||
|
||||
def test_decompress_eof_incomplete_stream(self):
|
||||
x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E' # 'foo'
|
||||
dco = zlib.decompressobj()
|
||||
self.assertFalse(dco.eof)
|
||||
dco.decompress(x[:-5])
|
||||
self.assertFalse(dco.eof)
|
||||
dco.flush()
|
||||
self.assertFalse(dco.eof)
|
||||
|
||||
if hasattr(zlib.compressobj(), "copy"):
|
||||
def test_compresscopy(self):
|
||||
# Test copying a compression object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue