From 72e3b69daf4f33d6df967cbaa22df628613c8040 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 2 Feb 2021 12:15:18 +0000 Subject: [PATCH] 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. --- mitogen/parent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 3b4dca8a..5baf2eb9 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -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)