Replace deprecated BadZipfile with BadZipFile (#80198)

* Replace deprecated BadZipfile with BadZipFile

* Retain support for Python 2.7
pull/80201/head
Hugo van Kemenade 1 year ago committed by GitHub
parent 7ce951ff48
commit 1c156c0d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -253,7 +253,7 @@ import stat
import time
import traceback
from functools import partial
from zipfile import ZipFile, BadZipfile
from zipfile import ZipFile
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.basic import AnsibleModule
@ -266,6 +266,11 @@ try: # python 3.3+
except ImportError: # older python
from pipes import quote
try: # python 3.2+
from zipfile import BadZipFile # type: ignore[attr-defined]
except ImportError: # older python
from zipfile import BadZipfile as BadZipFile
# String from tar that shows the tar contents are different from the
# filesystem
OWNER_DIFF_RE = re.compile(r': Uid differs$')
@ -351,7 +356,7 @@ class ZipArchive(object):
try:
archive = ZipFile(self.src)
except BadZipfile as e:
except BadZipFile as e:
if e.args[0].lower().startswith('bad magic number'):
# Python2.4 can't handle zipfiles with > 64K files. Try using
# /usr/bin/unzip instead
@ -376,7 +381,7 @@ class ZipArchive(object):
self._files_in_archive = []
try:
archive = ZipFile(self.src)
except BadZipfile as e:
except BadZipFile as e:
if e.args[0].lower().startswith('bad magic number'):
# Python2.4 can't handle zipfiles with > 64K files. Try using
# /usr/bin/unzip instead

Loading…
Cancel
Save