diff --git a/zipfile2/_zipfile.py b/zipfile2/_zipfile.py index c4b521c..ef72e12 100644 --- a/zipfile2/_zipfile.py +++ b/zipfile2/_zipfile.py @@ -5,6 +5,9 @@ import string import time import zipfile +import warnings + +from .common import PY311, metadata_encoding_warning ZIP_SOFTLINK_ATTRIBUTE_MAGIC = 0xA1ED0000 @@ -56,10 +59,18 @@ def __init__( archive. """ - super(ZipFile, self).__init__( - file, mode, compression, allowZip64, compresslevel, - strict_timestamps=strict_timestamps, - metadata_encoding=metadata_encoding) + if PY311: + super(ZipFile, self).__init__( + file, mode, compression, allowZip64, compresslevel, + strict_timestamps=strict_timestamps, + metadata_encoding=metadata_encoding) + else: + if metadata_encoding is not None: + warnings.warn(metadata_encoding_warning) + super(ZipFile, self).__init__( + file, mode, compression, allowZip64, compresslevel, + strict_timestamps=strict_timestamps) + self.low_level = low_level # Set of filenames currently in file diff --git a/zipfile2/common.py b/zipfile2/common.py index 47f0694..df6c9fe 100644 --- a/zipfile2/common.py +++ b/zipfile2/common.py @@ -4,7 +4,11 @@ PYTHON_VERSION = sys.version_info[:2] PY312 = PYTHON_VERSION >= (3, 12) +PY311 = PYTHON_VERSION >= (3, 11) class TooManyFiles(zipfile.BadZipfile): pass + + +metadata_encoding_warning = 'Python < 3.11 does not support the metadata_encoding' # noqa