diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py
index 8aec84078ed48f..fd8a96906ade65 100644
--- a/Lib/distutils/tests/test_archive_util.py
+++ b/Lib/distutils/tests/test_archive_util.py
@@ -30,11 +30,7 @@
except ImportError:
ZIP_SUPPORT = find_executable('zip')
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
+import zlib
try:
import bz2
@@ -63,7 +59,6 @@ class ArchiveUtilTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_make_tarball(self, name='archive'):
# creating something to tar
tmpdir = self._create_files()
@@ -71,7 +66,6 @@ def test_make_tarball(self, name='archive'):
# trying an uncompressed one
self._make_tarball(tmpdir, name, '.tar', compress=None)
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_make_tarball_gzip(self):
tmpdir = self._create_files()
self._make_tarball(tmpdir, 'archive', '.tar.gz', compress='gzip')
@@ -144,9 +138,8 @@ def _create_files(self):
os.mkdir(os.path.join(dist, 'sub2'))
return tmpdir
- @unittest.skipUnless(find_executable('tar') and find_executable('gzip')
- and ZLIB_SUPPORT,
- 'Need the tar, gzip and zlib command to run')
+ @unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
+ 'Need the tar and gzip commands to run')
def test_tarfile_vs_tar(self):
tmpdir = self._create_files()
tmpdir2 = self.mkdtemp()
@@ -234,8 +227,7 @@ def test_compress_deprecated(self):
self.assertFalse(os.path.exists(tarball))
self.assertEqual(len(w.warnings), 1)
- @unittest.skipUnless(ZIP_SUPPORT and ZLIB_SUPPORT,
- 'Need zip and zlib support to run')
+ @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
def test_make_zipfile(self):
# creating something to tar
tmpdir = self._create_files()
@@ -249,32 +241,6 @@ def test_make_zipfile(self):
with zipfile.ZipFile(tarball) as zf:
self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
- @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
- def test_make_zipfile_no_zlib(self):
- patch(self, archive_util.zipfile, 'zlib', None) # force zlib ImportError
-
- called = []
- zipfile_class = zipfile.ZipFile
- def fake_zipfile(*a, **kw):
- if kw.get('compression', None) == zipfile.ZIP_STORED:
- called.append((a, kw))
- return zipfile_class(*a, **kw)
-
- patch(self, archive_util.zipfile, 'ZipFile', fake_zipfile)
-
- # create something to tar and compress
- tmpdir = self._create_files()
- base_name = os.path.join(self.mkdtemp(), 'archive')
- with change_cwd(tmpdir):
- make_zipfile(base_name, 'dist')
-
- tarball = base_name + '.zip'
- self.assertEqual(called,
- [((tarball, "w"), {'compression': zipfile.ZIP_STORED})])
- self.assertTrue(os.path.exists(tarball))
- with zipfile.ZipFile(tarball) as zf:
- self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
-
def test_check_archive_formats(self):
self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']),
'xxx')
@@ -308,7 +274,6 @@ def test_make_archive_tar(self):
self.assertEqual(os.path.basename(res), 'archive.tar')
self.assertEqual(self._tarinfo(res), self._created_files)
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_make_archive_gztar(self):
base_dir = self._create_files()
base_name = os.path.join(self.mkdtemp() , 'archive')
@@ -362,7 +327,6 @@ def test_make_archive_owner_group(self):
owner='kjhkjhkjg', group='oihohoh')
self.assertTrue(os.path.exists(res))
- @unittest.skipUnless(ZLIB_SUPPORT, "Requires zlib")
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
def test_tarfile_root_owner(self):
tmpdir = self._create_files()
diff --git a/Lib/distutils/tests/test_bdist_dumb.py b/Lib/distutils/tests/test_bdist_dumb.py
index bb860c8ac70345..181ea6fd20256c 100644
--- a/Lib/distutils/tests/test_bdist_dumb.py
+++ b/Lib/distutils/tests/test_bdist_dumb.py
@@ -2,8 +2,9 @@
import os
import sys
-import zipfile
import unittest
+import zipfile
+import zlib
from test.support import run_unittest
from distutils.core import Distribution
@@ -19,11 +20,6 @@
"""
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
class BuildDumbTestCase(support.TempdirManager,
@@ -42,7 +38,6 @@ def tearDown(self):
sys.argv[:] = self.old_sys_argv[1]
super(BuildDumbTestCase, self).tearDown()
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_simple_built(self):
# let's create a simple package
diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py
index f1eb9ba4493828..f3743900ae87b6 100644
--- a/Lib/distutils/tests/test_bdist_rpm.py
+++ b/Lib/distutils/tests/test_bdist_rpm.py
@@ -3,7 +3,7 @@
import unittest
import sys
import os
-from test.support import run_unittest, requires_zlib
+from test.support import run_unittest
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
@@ -44,7 +44,6 @@ def tearDown(self):
# spurious sdtout/stderr output under Mac OS X
@unittest.skipUnless(sys.platform.startswith('linux'),
'spurious sdtout/stderr output under Mac OS X')
- @requires_zlib()
@unittest.skipIf(find_executable('rpm') is None,
'the rpm command is not found')
@unittest.skipIf(find_executable('rpmbuild') is None,
@@ -87,7 +86,6 @@ def test_quiet(self):
# spurious sdtout/stderr output under Mac OS X
@unittest.skipUnless(sys.platform.startswith('linux'),
'spurious sdtout/stderr output under Mac OS X')
- @requires_zlib()
# http://bugs.python.org/issue1533164
@unittest.skipIf(find_executable('rpm') is None,
'the rpm command is not found')
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index 46b3a13e470c4e..e75916debb4114 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -4,17 +4,12 @@
import unittest
import warnings
import zipfile
+import zlib
from os.path import join
from textwrap import dedent
from test.support import captured_stdout, run_unittest
from test.support.warnings_helper import check_warnings
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
-
try:
import grp
import pwd
@@ -88,7 +83,6 @@ def get_cmd(self, metadata=None):
cmd.dist_dir = 'dist'
return dist, cmd
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_prune_file_list(self):
# this test creates a project with some VCS dirs and an NFS rename
# file, then launches sdist to check they get pruned on all systems
@@ -133,7 +127,6 @@ def test_prune_file_list(self):
'somecode/', 'somecode/__init__.py']
self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
@unittest.skipIf(find_executable('tar') is None,
"The tar command is not found")
@unittest.skipIf(find_executable('gzip') is None,
@@ -166,7 +159,6 @@ def test_make_distribution(self):
result.sort()
self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_add_defaults(self):
# http://bugs.python.org/issue2279
@@ -245,7 +237,6 @@ def test_add_defaults(self):
f.close()
self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_metadata_check_option(self):
# testing the `medata-check` option
dist, cmd = self.get_cmd(metadata={})
@@ -332,7 +323,6 @@ def test_invalid_template_wrong_path(self):
# this used to crash instead of raising a warning: #8286
self._check_template('include examples/')
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_get_file_list(self):
# make sure MANIFEST is recalculated
dist, cmd = self.get_cmd()
@@ -374,7 +364,6 @@ def test_get_file_list(self):
self.assertEqual(len(manifest2), 6)
self.assertIn('doc2.txt', manifest2[-1])
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_manifest_marker(self):
# check that autogenerated MANIFESTs have a marker
dist, cmd = self.get_cmd()
@@ -391,7 +380,6 @@ def test_manifest_marker(self):
self.assertEqual(manifest[0],
'# file GENERATED by distutils, do NOT edit')
- @unittest.skipUnless(ZLIB_SUPPORT, "Need zlib support to run")
def test_manifest_comments(self):
# make sure comments don't cause exceptions or wrong includes
contents = dedent("""\
@@ -408,7 +396,6 @@ def test_manifest_comments(self):
cmd.run()
self.assertEqual(cmd.filelist.files, ['good.py'])
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_manual_manifest(self):
# check that a MANIFEST without a marker is left alone
dist, cmd = self.get_cmd()
@@ -438,7 +425,6 @@ def test_manual_manifest(self):
self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
'fake-1.0/README.manual'])
- @unittest.skipUnless(ZLIB_SUPPORT, "requires zlib")
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
@unittest.skipIf(find_executable('tar') is None,
"The tar command is not found")
diff --git a/Lib/encodings/zlib_codec.py b/Lib/encodings/zlib_codec.py
index 95908a4b4a13a1..25acfba1c01483 100644
--- a/Lib/encodings/zlib_codec.py
+++ b/Lib/encodings/zlib_codec.py
@@ -6,7 +6,7 @@
"""
import codecs
-import zlib # this codec needs the optional zlib module !
+import zlib
### Codec APIs
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 22bd86d569e7ed..1c0945837cd601 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -10,13 +10,7 @@
import fnmatch
import collections
import errno
-
-try:
- import zlib
- del zlib
- _ZLIB_SUPPORTED = True
-except ImportError:
- _ZLIB_SUPPORTED = False
+import zlib
try:
import bz2
@@ -911,7 +905,7 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
"""
if compress is None:
tar_compression = ''
- elif _ZLIB_SUPPORTED and compress == 'gzip':
+ elif compress == 'gzip':
tar_compression = 'gz'
elif _BZ2_SUPPORTED and compress == 'bzip2':
tar_compression = 'bz2'
@@ -1006,10 +1000,9 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
}
-if _ZLIB_SUPPORTED:
- _ARCHIVE_FORMATS['gztar'] = (_make_tarball, [('compress', 'gzip')],
- "gzip'ed tar-file")
- _ARCHIVE_FORMATS['zip'] = (_make_zipfile, [], "ZIP file")
+_ARCHIVE_FORMATS['gztar'] = (_make_tarball, [('compress', 'gzip')],
+ "gzip'ed tar-file")
+_ARCHIVE_FORMATS['zip'] = (_make_zipfile, [], "ZIP file")
if _BZ2_SUPPORTED:
_ARCHIVE_FORMATS['bztar'] = (_make_tarball, [('compress', 'bzip2')],
@@ -1217,12 +1210,9 @@ def _unpack_tarfile(filename, extract_dir):
_UNPACK_FORMATS = {
'tar': (['.tar'], _unpack_tarfile, [], "uncompressed tar file"),
'zip': (['.zip'], _unpack_zipfile, [], "ZIP file"),
+ 'gztar': (['.tar.gz', '.tgz'], _unpack_tarfile, [], "gzip'ed tar-file"),
}
-if _ZLIB_SUPPORTED:
- _UNPACK_FORMATS['gztar'] = (['.tar.gz', '.tgz'], _unpack_tarfile, [],
- "gzip'ed tar-file")
-
if _BZ2_SUPPORTED:
_UNPACK_FORMATS['bztar'] = (['.tar.bz2', '.tbz2'], _unpack_tarfile, [],
"bzip2'ed tar-file")
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 8d43d0da7b9880..f96be649fbe5d0 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -361,10 +361,7 @@ def __init__(self, name, mode, comptype, fileobj, bufsize):
try:
if comptype == "gz":
- try:
- import zlib
- except ImportError:
- raise CompressionError("zlib module is not available") from None
+ import zlib
self.zlib = zlib
self.crc = zlib.crc32(b"")
if mode == "r":
@@ -2359,13 +2356,10 @@ def next(self):
except SubsequentHeaderError as e:
raise ReadError(str(e)) from None
except Exception as e:
- try:
- import zlib
- if isinstance(e, zlib.error):
- raise ReadError(f'zlib error: {e}') from None
- else:
- raise e
- except ImportError:
+ import zlib
+ if isinstance(e, zlib.error):
+ raise ReadError(f'zlib error: {e}') from None
+ else:
raise e
break
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index d15a11c80b649a..f2d6dd6ce87ebc 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -1,7 +1,6 @@
"""
Collect various information about Python to help debugging test failures.
"""
-from __future__ import print_function
import errno
import re
import sys
@@ -558,11 +557,7 @@ def collect_sqlite(info_add):
def collect_zlib(info_add):
- try:
- import zlib
- except ImportError:
- return
-
+ import zlib
attributes = ('ZLIB_VERSION', 'ZLIB_RUNTIME_VERSION')
copy_attributes(info_add, zlib, 'zlib.%s', attributes)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 5853e088197153..8b4ec2bbc30a3f 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2700,13 +2700,10 @@ def test_seek0(self):
"rot_13": ["rot13"],
}
-try:
- import zlib
-except ImportError:
- zlib = None
-else:
- bytes_transform_encodings.append("zlib_codec")
- transform_aliases["zlib_codec"] = ["zip", "zlib"]
+import zlib
+bytes_transform_encodings.append("zlib_codec")
+transform_aliases["zlib_codec"] = ["zip", "zlib"]
+
try:
import bz2
except ImportError:
@@ -2807,7 +2804,6 @@ def test_binary_to_text_denylists_text_transforms(self):
bad_input.decode("rot_13")
self.assertIsNone(failure.exception.__cause__)
- @unittest.skipUnless(zlib, "Requires zlib support")
def test_custom_zlib_error_is_wrapped(self):
# Check zlib codec gives a good error for malformed input
msg = "^decoding with 'zlib_codec' codec failed"
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py
index 803d3738d263f4..df66ab316272db 100644
--- a/Lib/test/test_importlib/fixtures.py
+++ b/Lib/test/test_importlib/fixtures.py
@@ -8,7 +8,6 @@
import contextlib
from test.support.os_helper import FS_NONASCII
-from test.support import requires_zlib
from typing import Dict, Union
try:
@@ -281,7 +280,6 @@ def find_module(self, name):
pass
-@requires_zlib()
class ZipFixtures:
root = 'test.test_importlib.data'
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index be193dcdacf4f0..a03262d5b2fb68 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -70,10 +70,8 @@
except ImportError:
win32evtlog = win32evtlogutil = pywintypes = None
-try:
- import zlib
-except ImportError:
- pass
+import zlib
+
class BaseTest(unittest.TestCase):
@@ -5311,7 +5309,6 @@ def rotator(self, source, dest):
self.assertFalse(os.path.exists(rh.namer(self.fn + ".1")))
rh.close()
- @support.requires_zlib()
def test_rotator(self):
def namer(name):
return name + ".gz"
diff --git a/Lib/test/test_sqlite3/test_types.py b/Lib/test/test_sqlite3/test_types.py
index 0cfb72c5f0999e..def4dc7fcd64c1 100644
--- a/Lib/test/test_sqlite3/test_types.py
+++ b/Lib/test/test_sqlite3/test_types.py
@@ -24,10 +24,7 @@
import unittest
import sqlite3 as sqlite
import sys
-try:
- import zlib
-except ImportError:
- zlib = None
+import zlib
from test import support
@@ -466,7 +463,6 @@ def test_adapt_alt(self):
self.assertEqual(alt, sqlite.adapt(1., None, alt))
-@unittest.skipUnless(zlib, "requires zlib")
class BinaryConverterTests(unittest.TestCase):
def convert(s):
return zlib.decompress(s)
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 12850cd635e995..6980fbf8e7644f 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -15,14 +15,8 @@
from test.support import script_helper
# Check for our compression modules.
-try:
- import gzip
-except ImportError:
- gzip = None
-try:
- import zlib
-except ImportError:
- zlib = None
+import gzip
+import zlib
try:
import bz2
except ImportError:
@@ -62,7 +56,6 @@ class TarTest:
def mode(self):
return self.prefix + self.suffix
-@support.requires_gzip()
class GzipTest:
tarname = gzipname
suffix = 'gz'
@@ -722,7 +715,6 @@ def test_parallel_iteration(self):
self.assertEqual(m1.offset, m2.offset)
self.assertEqual(m1.get_info(), m2.get_info())
- @unittest.skipIf(zlib is None, "requires zlib")
def test_zlib_error_does_not_leak(self):
# bpo-39039: tarfile.open allowed zlib exceptions to bubble up when
# parsing certain types of invalid data
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index db812f21dbc562..f1d2467a55fab3 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -14,7 +14,7 @@
import subprocess
import sys
import tempfile
-from test.support import (captured_stdout, captured_stderr, requires_zlib,
+from test.support import (captured_stdout, captured_stderr,
skip_if_broken_multiprocessing_synchronize, verbose,
requires_subprocess)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
@@ -596,7 +596,6 @@ def do_test_with_pip(self, system_site_packages):
# Issue #26610: pip/pep425tags.py requires ctypes
@unittest.skipUnless(ctypes, 'pip requires ctypes')
- @requires_zlib()
def test_with_pip(self):
self.do_test_with_pip(False)
self.do_test_with_pip(True)
diff --git a/Lib/test/test_zipapp.py b/Lib/test/test_zipapp.py
index 69f2e55d563840..2df254660f402a 100644
--- a/Lib/test/test_zipapp.py
+++ b/Lib/test/test_zipapp.py
@@ -8,7 +8,6 @@
import unittest
import zipapp
import zipfile
-from test.support import requires_zlib
from unittest.mock import patch
@@ -101,7 +100,6 @@ def test_create_archive_default_target(self):
expected_target = self.tmpdir / 'source.pyz'
self.assertTrue(expected_target.is_file())
- @requires_zlib()
def test_create_archive_with_compression(self):
# Test packing a directory into a compressed archive.
source = self.tmpdir / 'source'
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 759a4abb9d4d4e..a832b902011a0b 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -21,7 +21,7 @@
from random import randint, random, randbytes
from test.support import script_helper
-from test.support import (findfile, requires_zlib, requires_bz2,
+from test.support import (findfile, requires_bz2,
requires_lzma, captured_stdout, requires_subprocess)
from test.support.os_helper import (
TESTFN, unlink, rmtree, temp_dir, temp_cwd, fd_count
@@ -645,7 +645,6 @@ def test_add_file_after_2107(self):
self.assertEqual(zinfo.date_time, (2107, 12, 31, 23, 59, 59))
-@requires_zlib()
class DeflateTestsWithSourceFile(AbstractTestsWithSourceFile,
unittest.TestCase):
compression = zipfile.ZIP_DEFLATED
@@ -1080,7 +1079,6 @@ def test_generated_valid_zip64_extra(self):
self.assertEqual(zf.read(zinfo), expected_content)
-@requires_zlib()
class DeflateTestZip64InSmallFiles(AbstractTestZip64InSmallFiles,
unittest.TestCase):
compression = zipfile.ZIP_DEFLATED
@@ -1133,7 +1131,6 @@ def test_issue44439(self):
class StoredWriterTests(AbstractWriterTests, unittest.TestCase):
compression = zipfile.ZIP_STORED
-@requires_zlib()
class DeflateWriterTests(AbstractWriterTests, unittest.TestCase):
compression = zipfile.ZIP_DEFLATED
@@ -1595,7 +1592,6 @@ def test_unsupported_version(self):
self.assertRaises(NotImplementedError, zipfile.ZipFile,
io.BytesIO(data), 'r')
- @requires_zlib()
def test_read_unicode_filenames(self):
# bug #10801
fname = findfile('zip_cp437_header.zip')
@@ -2097,7 +2093,6 @@ class StoredBadCrcTests(AbstractBadCrcTests, unittest.TestCase):
b'lePK\005\006\0\0\0\0\001\0\001\0003\000'
b'\0\0/\0\0\0\0\0')
-@requires_zlib()
class DeflateBadCrcTests(AbstractBadCrcTests, unittest.TestCase):
compression = zipfile.ZIP_DEFLATED
zip_with_bad_crc = (
@@ -2193,7 +2188,6 @@ def test_bad_password(self):
self.zip2.setpassword(b"perl")
self.assertRaises(RuntimeError, self.zip2.read, "zero")
- @requires_zlib()
def test_good_password(self):
self.zip.setpassword(b"python")
self.assertEqual(self.zip.read("test.txt"), self.plain)
@@ -2352,7 +2346,6 @@ class StoredTestsWithRandomBinaryFiles(AbstractTestsWithRandomBinaryFiles,
unittest.TestCase):
compression = zipfile.ZIP_STORED
-@requires_zlib()
class DeflateTestsWithRandomBinaryFiles(AbstractTestsWithRandomBinaryFiles,
unittest.TestCase):
compression = zipfile.ZIP_DEFLATED
@@ -2450,7 +2443,6 @@ def test_open_write(self):
self.assertEqual(zipf.read('twos'), b'222')
-@requires_zlib()
class TestsWithMultipleOpens(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -2716,7 +2708,6 @@ def test_list_command(self):
PYTHONIOENCODING='ascii:backslashreplace')
self.assertEqual(out, expected)
- @requires_zlib()
def test_create_command(self):
self.addCleanup(unlink, TESTFN)
with open(TESTFN, 'w', encoding='utf-8') as f:
diff --git a/Lib/test/test_zipfile64.py b/Lib/test/test_zipfile64.py
index 0947013afbc6ed..dd3f460f598d1b 100644
--- a/Lib/test/test_zipfile64.py
+++ b/Lib/test/test_zipfile64.py
@@ -18,7 +18,6 @@
from tempfile import TemporaryFile
from test.support import os_helper
-from test.support import requires_zlib
TESTFN = os_helper.TESTFN
TESTFN2 = TESTFN + "2"
@@ -75,7 +74,6 @@ def testStored(self):
self.assertFalse(f.closed)
self.zipTest(TESTFN2, zipfile.ZIP_STORED)
- @requires_zlib()
def testDeflated(self):
# Try the temp file first. If we do TESTFN2 first, then it hogs
# gigabytes of disk space for the duration of the test.
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 85dbf4d8f68eb6..2991a58dd75183 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -21,10 +21,7 @@
import inspect
import io
from traceback import extract_tb, extract_stack, print_tb
-try:
- import zlib
-except ImportError:
- zlib = None
+import zlib
test_src = """\
def get_name():
@@ -774,7 +771,6 @@ def testLargestPossibleComment(self):
self.doTest(".py", files, TESTMOD, comment=b"c" * ((1 << 16) - 1))
-@support.requires_zlib()
class CompressedZipImportTestCase(UncompressedZipImportTestCase):
compression = ZIP_DEFLATED
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 385adc897317fd..3ddfafac43b4cf 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -17,13 +17,8 @@
import time
import contextlib
import pathlib
-
-try:
- import zlib # We may need its compression method
- crc32 = zlib.crc32
-except ImportError:
- zlib = None
- crc32 = binascii.crc32
+import zlib
+crc32 = zlib.crc32
try:
import bz2 # We may need its compression method
@@ -687,12 +682,8 @@ def decompress(self, data):
}
def _check_compression(compression):
- if compression == ZIP_STORED:
+ if compression in (ZIP_STORED, ZIP_DEFLATED):
pass
- elif compression == ZIP_DEFLATED:
- if not zlib:
- raise RuntimeError(
- "Compression requires the (missing) zlib module")
elif compression == ZIP_BZIP2:
if not bz2:
raise RuntimeError(
diff --git a/Lib/zipimport.py b/Lib/zipimport.py
index 25eaee9c0f291b..edbf1c6f05369c 100644
--- a/Lib/zipimport.py
+++ b/Lib/zipimport.py
@@ -554,9 +554,7 @@ def _read_directory(archive):
_importing_zlib = False
-# Return the zlib.decompress function object, or NULL if zlib couldn't
-# be imported. The function is cached when found, so subsequent calls
-# don't import zlib again.
+# Return the zlib.decompress function object or raise an import error.
def _get_decompress_func():
global _importing_zlib
if _importing_zlib:
@@ -568,9 +566,6 @@ def _get_decompress_func():
_importing_zlib = True
try:
from zlib import decompress
- except Exception:
- _bootstrap._verbose_message('zipimport: zlib UNAVAILABLE')
- raise ZipImportError("can't decompress data; zlib not available")
finally:
_importing_zlib = False
diff --git a/Modules/Setup.bootstrap.in b/Modules/Setup.bootstrap.in
index ec724978f319b4..1bfcb357480be1 100644
--- a/Modules/Setup.bootstrap.in
+++ b/Modules/Setup.bootstrap.in
@@ -22,6 +22,8 @@ _sre _sre.c
_thread _threadmodule.c
time timemodule.c
_weakref _weakref.c
+# used by shutil
+zlib zlibmodule.c
# commonly used core modules
_abc _abc.c
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 73f041eb2fba9f..6f0ce1ea079034 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -59,12 +59,11 @@
# with ./configure --with-system-libmpdec
@MODULE__DECIMAL_TRUE@_decimal _decimal/_decimal.c
-# compression libs and binascii (optional CRC32 from zlib)
+# compression libs and binascii (CRC32 from zlib)
# bindings need -lbz2, -lz, or -llzma, respectively
@MODULE_BINASCII_TRUE@binascii binascii.c
@MODULE__BZ2_TRUE@_bz2 _bz2module.c
@MODULE__LZMA_TRUE@_lzma _lzmamodule.c
-@MODULE_ZLIB_TRUE@zlib zlibmodule.c
# dbm/gdbm
# dbm needs either libndbm, libgdbm_compat, or libdb 5.x
diff --git a/Modules/binascii.c b/Modules/binascii.c
index afe49885491714..3f0678d0d97d0e 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -62,9 +62,7 @@
#include "Python.h"
#include "pycore_long.h" // _PyLong_DigitValue
#include "pycore_strhex.h" // _Py_strhex_bytes_with_sep()
-#ifdef USE_ZLIB_CRC32
-# include "zlib.h"
-#endif
+#include "zlib.h" // crc32()
typedef struct binascii_state {
PyObject *Error;
@@ -619,140 +617,6 @@ binascii_crc_hqx_impl(PyObject *module, Py_buffer *data, unsigned int crc)
return PyLong_FromUnsignedLong(crc);
}
-#ifndef USE_ZLIB_CRC32
-/* Crc - 32 BIT ANSI X3.66 CRC checksum files
- Also known as: ISO 3307
-**********************************************************************|
-* *|
-* Demonstration program to compute the 32-bit CRC used as the frame *|
-* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71 *|
-* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level *|
-* protocol). The 32-bit FCS was added via the Federal Register, *|
-* 1 June 1982, p.23798. I presume but don't know for certain that *|
-* this polynomial is or will be included in CCITT V.41, which *|
-* defines the 16-bit CRC (often called CRC-CCITT) polynomial. FIPS *|
-* PUB 78 says that the 32-bit FCS reduces otherwise undetected *|
-* errors by a factor of 10^-5 over 16-bit FCS. *|
-* *|
-**********************************************************************|
-
- Copyright (C) 1986 Gary S. Brown. You may use this program, or
- code or tables extracted from it, as desired without restriction.
-
- First, the polynomial itself and its table of feedback terms. The
- polynomial is
- X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
- Note that we take it "backwards" and put the highest-order term in
- the lowest-order bit. The X^32 term is "implied"; the LSB is the
- X^31 term, etc. The X^0 term (usually shown as "+1") results in
- the MSB being 1.
-
- Note that the usual hardware shift register implementation, which
- is what we're using (we're merely optimizing it by doing eight-bit
- chunks at a time) shifts bits into the lowest-order term. In our
- implementation, that means shifting towards the right. Why do we
- do it this way? Because the calculated CRC must be transmitted in
- order from highest-order term to lowest-order term. UARTs transmit
- characters in order from LSB to MSB. By storing the CRC this way,
- we hand it to the UART in the order low-byte to high-byte; the UART
- sends each low-bit to hight-bit; and the result is transmission bit
- by bit from highest- to lowest-order term without requiring any bit
- shuffling on our part. Reception works similarly.
-
- The feedback terms table consists of 256, 32-bit entries. Notes:
-
- 1. The table can be generated at runtime if desired; code to do so
- is shown later. It might not be obvious, but the feedback
- terms simply represent the results of eight shift/xor opera-
- tions for all combinations of data and CRC register values.
-
- 2. The CRC accumulation logic is the same for all CRC polynomials,
- be they sixteen or thirty-two bits wide. You simply choose the
- appropriate table. Alternatively, because the table can be
- generated at runtime, you can start by generating the table for
- the polynomial in question and use exactly the same "updcrc",
- if your application needn't simultaneously handle two CRC
- polynomials. (Note, however, that XMODEM is strange.)
-
- 3. For 16-bit CRCs, the table entries need be only 16 bits wide;
- of course, 32-bit entries work OK if the high 16 bits are zero.
-
- 4. The values must be right-shifted by eight bits by the "updcrc"
- logic; the shift must be unsigned (bring in zeroes). On some
- hardware you could probably optimize the shift in assembler by
- using byte-swap instructions.
-********************************************************************/
-
-static const unsigned int crc_32_tab[256] = {
-0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
-0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
-0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
-0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
-0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
-0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
-0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
-0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
-0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
-0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
-0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
-0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
-0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
-0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
-0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
-0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
-0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
-0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
-0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
-0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
-0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
-0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
-0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
-0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
-0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
-0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
-0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
-0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
-0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
-0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
-0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
-0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
-0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
-0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
-0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
-0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
-0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
-0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
-0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
-0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
-0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
-0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
-0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
-0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
-0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
-0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
-0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
-0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
-0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
-0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
-0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
-0x2d02ef8dU
-};
-
-static unsigned int
-internal_crc32(const unsigned char *bin_data, Py_ssize_t len, unsigned int crc)
-{ /* By Jim Ahlstrom; All rights transferred to CNRI */
- unsigned int result;
-
- crc = ~ crc;
- while (len-- > 0) {
- crc = crc_32_tab[(crc ^ *bin_data++) & 0xff] ^ (crc >> 8);
- /* Note: (crc >> 8) MUST zero fill on left */
- }
-
- result = (crc ^ 0xFFFFFFFF);
- return result & 0xffffffff;
-}
-#endif /* USE_ZLIB_CRC32 */
/*[clinic input]
binascii.crc32 -> unsigned_int
@@ -767,10 +631,8 @@ Compute CRC-32 incrementally.
static unsigned int
binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc)
/*[clinic end generated code: output=52cf59056a78593b input=bbe340bc99d25aa8]*/
-
-#ifdef USE_ZLIB_CRC32
/* This is the same as zlibmodule.c zlib_crc32_impl. It exists in two
- * modules for historical reasons. */
+ * modules for historical reasons. We should consolidate the two. */
{
/* Releasing the GIL for very small buffers is inefficient
and may lower performance */
@@ -793,24 +655,6 @@ binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc)
}
return crc & 0xffffffff;
}
-#else /* USE_ZLIB_CRC32 */
-{
- const unsigned char *bin_data = data->buf;
- Py_ssize_t len = data->len;
-
- /* Releasing the GIL for very small buffers is inefficient
- and may lower performance */
- if (len > 1024*5) {
- unsigned int result;
- Py_BEGIN_ALLOW_THREADS
- result = internal_crc32(bin_data, len, crc);
- Py_END_ALLOW_THREADS
- return result;
- } else {
- return internal_crc32(bin_data, len, crc);
- }
-}
-#endif /* USE_ZLIB_CRC32 */
/*[clinic input]
binascii.b2a_hex
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 5e6e703df9123e..a0a230134290bf 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -366,9 +366,7 @@
-
- USE_ZLIB_CRC32;%(PreprocessorDefinitions)
-
+
diff --git a/configure b/configure
index 5fa6efaab4fb7c..815dc4c0b6a7bb 100755
--- a/configure
+++ b/configure
@@ -14863,7 +14863,6 @@ fi
$as_echo "$ac_cv_lib_z_gzread" >&6; }
if test "x$ac_cv_lib_z_gzread" = xyes; then :
- have_zlib=yes
ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
@@ -14910,7 +14909,7 @@ fi
else
- have_zlib=no
+ as_fn_error $? "zlib.h and libz are required. Install your OS's zlib-devel or zlib1g-dev equivalent library or get it from https://zlib.net/." "$LINENO" 5
fi
@@ -14923,7 +14922,9 @@ LIBS=$save_LIBS
else
- have_zlib=no
+
+ as_fn_error $? "zlib.h and libz are required. Install your OS's zlib-devel or zlib1g-dev equivalent library or get it from https://zlib.net/." "$LINENO" 5
+
fi
done
@@ -14985,7 +14986,6 @@ fi
$as_echo "$ac_cv_lib_z_gzread" >&6; }
if test "x$ac_cv_lib_z_gzread" = xyes; then :
- have_zlib=yes
ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inflateCopy in -lz" >&5
@@ -15032,7 +15032,7 @@ fi
else
- have_zlib=no
+ as_fn_error $? "zlib.h and libz are required. Install your OS's zlib-devel or zlib1g-dev equivalent library or get it from https://zlib.net/." "$LINENO" 5
fi
@@ -15045,7 +15045,9 @@ LIBS=$save_LIBS
else
- have_zlib=no
+
+ as_fn_error $? "zlib.h and libz are required. Install your OS's zlib-devel or zlib1g-dev equivalent library or get it from https://zlib.net/." "$LINENO" 5
+
fi
done
@@ -15057,19 +15059,11 @@ else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- have_zlib=yes
$as_echo "#define HAVE_ZLIB_COPY 1" >>confdefs.h
fi
-if test "x$have_zlib" = xyes; then :
-
- BINASCII_CFLAGS="-DUSE_ZLIB_CRC32 $ZLIB_CFLAGS"
- BINASCII_LIBS="$ZLIB_LIBS"
-
-fi
-
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZIP2" >&5
@@ -23054,21 +23048,17 @@ $as_echo "$py_cv_module__uuid" >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module zlib" >&5
-$as_echo_n "checking for stdlib extension module zlib... " >&6; }
if test "$py_cv_module_zlib" != "n/a"; then :
-
- if true; then :
- if test "$have_zlib" = yes; then :
py_cv_module_zlib=yes
-else
- py_cv_module_zlib=missing
fi
+ if test "$py_cv_module_zlib" = yes; then
+ MODULE_ZLIB_TRUE=
+ MODULE_ZLIB_FALSE='#'
else
- py_cv_module_zlib=disabled
+ MODULE_ZLIB_TRUE='#'
+ MODULE_ZLIB_FALSE=
fi
-fi
as_fn_append MODULE_BLOCK "MODULE_ZLIB=$py_cv_module_zlib$as_nl"
if test "x$py_cv_module_zlib" = xyes; then :
@@ -23076,16 +23066,6 @@ fi
as_fn_append MODULE_BLOCK "MODULE_ZLIB_LDFLAGS=$ZLIB_LIBS$as_nl"
fi
- if test "$py_cv_module_zlib" = yes; then
- MODULE_ZLIB_TRUE=
- MODULE_ZLIB_FALSE='#'
-else
- MODULE_ZLIB_TRUE='#'
- MODULE_ZLIB_FALSE=
-fi
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module_zlib" >&5
-$as_echo "$py_cv_module_zlib" >&6; }
if test "$py_cv_module_binascii" != "n/a"; then :
@@ -23102,8 +23082,8 @@ fi
as_fn_append MODULE_BLOCK "MODULE_BINASCII=$py_cv_module_binascii$as_nl"
if test "x$py_cv_module_binascii" = xyes; then :
- as_fn_append MODULE_BLOCK "MODULE_BINASCII_CFLAGS=$BINASCII_CFLAGS$as_nl"
- as_fn_append MODULE_BLOCK "MODULE_BINASCII_LDFLAGS=$BINASCII_LIBS$as_nl"
+ as_fn_append MODULE_BLOCK "MODULE_BINASCII_CFLAGS=$ZLIB_CFLAGS$as_nl"
+ as_fn_append MODULE_BLOCK "MODULE_BINASCII_LDFLAGS=$ZLIB_LIBS$as_nl"
fi
diff --git a/configure.ac b/configure.ac
index 7a37ad279d0fcb..2d4836e08b9c91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4333,31 +4333,33 @@ if test "$ac_cv_have_lchflags" = yes ; then
fi
dnl Check for compression libraries
-AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy])
+AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy; zlib 1.2.0 (2003) added inflateCopy.])
+dnl 2022-03: Until we know if third party zlib modules people use (for hardware
+dnl accelerators, parallelism, etc.) all support copy, lets not assume.
PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.0], [
- have_zlib=yes
dnl zlib 1.2.0 (2003) added inflateCopy
AC_DEFINE([HAVE_ZLIB_COPY], [1])
], [
AC_CHECK_HEADERS([zlib.h], [
WITH_SAVE_ENV([
AC_CHECK_LIB([z], [gzread], [
- have_zlib=yes
ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
AC_CHECK_LIB([z], [inflateCopy], [AC_DEFINE([HAVE_ZLIB_COPY], [1])])
], [
- have_zlib=no
+ AC_MSG_ERROR([m4_normalize([
+ zlib.h and libz are required. Install your OS's zlib-devel or
+ zlib1g-dev equivalent library or get it from https://zlib.net/.
+ ])])
])
])
- ], [have_zlib=no])
-])
-
-dnl binascii can use zlib for optimized crc32.
-AS_VAR_IF([have_zlib], [yes], [
- BINASCII_CFLAGS="-DUSE_ZLIB_CRC32 $ZLIB_CFLAGS"
- BINASCII_LIBS="$ZLIB_LIBS"
+ ], [
+ AC_MSG_ERROR([m4_normalize([
+ zlib.h and libz are required. Install your OS's zlib-devel or
+ zlib1g-dev equivalent library or get it from https://zlib.net/.
+ ])])
+ ])
])
PKG_CHECK_MODULES([BZIP2], [bzip2], [have_bzip2=yes], [
@@ -6619,10 +6621,9 @@ PY_STDLIB_MOD([_uuid],
[$LIBUUID_CFLAGS], [$LIBUUID_LIBS])
dnl compression libs
-PY_STDLIB_MOD([zlib], [], [test "$have_zlib" = yes],
- [$ZLIB_CFLAGS], [$ZLIB_LIBS])
-dnl binascii can use zlib for optimized crc32.
-PY_STDLIB_MOD_SIMPLE([binascii], [$BINASCII_CFLAGS], [$BINASCII_LIBS])
+PY_STDLIB_MOD_SIMPLE([zlib], [$ZLIB_CFLAGS], [$ZLIB_LIBS])
+dnl binascii uses zlib for optimized crc32.
+PY_STDLIB_MOD_SIMPLE([binascii], [$ZLIB_CFLAGS], [$ZLIB_LIBS])
PY_STDLIB_MOD([_bz2], [], [test "$have_bzip2" = yes],
[$BZIP2_CFLAGS], [$BZIP2_LIBS])
PY_STDLIB_MOD([_lzma], [], [test "$have_liblzma" = yes],
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 40952883853e32..afafd860e396a6 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -1441,7 +1441,8 @@
/* Define to 1 if you have the `writev' function. */
#undef HAVE_WRITEV
-/* Define if the zlib library has inflateCopy */
+/* Define if the zlib library has inflateCopy; zlib 1.2.0 (2003) added
+ inflateCopy. */
#undef HAVE_ZLIB_COPY
/* Define to 1 if you have the header file. */
diff --git a/setup.py b/setup.py
index c3cf2417bc429d..b1fae7b9d5adcf 100644
--- a/setup.py
+++ b/setup.py
@@ -1350,11 +1350,8 @@ def detect_platform_specific_exts(self):
self.addext(Extension('_scproxy', ['_scproxy.c']))
def detect_compress_exts(self):
- # Andrew Kuchling's zlib module.
- self.addext(Extension('zlib', ['zlibmodule.c']))
-
- # Helper module for various ascii-encoders. Uses zlib for an optimized
- # crc32 if we have it. Otherwise binascii uses its own.
+ # The zlib module is built by our Makefile
+ # Helper module for various ascii-encoders. Uses zlib for crc32.
self.addext(Extension('binascii', ['binascii.c']))
# Gustavo Niemeyer's bz2 module.