Skip to content

Commit

Permalink
Fix compatibility with Python < 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos committed Oct 5, 2024
1 parent d0eb7b2 commit 97f5027
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 15 additions & 4 deletions zipfile2/_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import string
import time
import zipfile
import warnings

from .common import PY311, metadata_encoding_warning

ZIP_SOFTLINK_ATTRIBUTE_MAGIC = 0xA1ED0000

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions zipfile2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 97f5027

Please sign in to comment.