issue #768: use feature detection for Compress.copy()

Work around a seemingly impossible condition by feature detecting
zlib.compressobj().copy rather than assuming it is available in all
Python releases. The related ticket looks possibly like some weird
vendor-patched version of Python in use, which has happened in the past
particularly on Red Hat.
dmw
David Wilson 4 years ago
parent 091ae234fc
commit 72e3b69daf

@ -692,9 +692,11 @@ class PartialZlib(object):
A full compression costs ~6ms on a modern machine, this method costs ~35
usec.
"""
HAS_COPY = hasattr(zlib.compressobj(), 'copy')
def __init__(self, s):
self.s = s
if sys.version_info > (2, 5):
if self.HAS_COPY:
self._compressor = zlib.compressobj(9)
self._out = self._compressor.compress(s)
self._out += self._compressor.flush(zlib.Z_SYNC_FLUSH)

Loading…
Cancel
Save