1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6180/f66cc7c9 backport][stable-5] Replace deprecated error with BadZipFile (#6215)

Replace deprecated error with BadZipFile (#6180)

* Replace deprecated error with BadZipFile

* Use imported BadZipFile

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add news fragment

* Update new fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit f66cc7c933)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-03-22 13:15:55 +01:00 committed by GitHub
parent 8ce81d24f2
commit 3e740112a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "archive - avoid deprecated exception class on Python 3 (https://github.com/ansible-collections/community.general/pull/6180)."

View file

@ -191,6 +191,10 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.text.converters import to_bytes, to_native from ansible.module_utils.common.text.converters import to_bytes, to_native
from ansible.module_utils import six from ansible.module_utils import six
try: # python 3.2+
from zipfile import BadZipFile # type: ignore[attr-defined]
except ImportError: # older python
from zipfile import BadZipfile as BadZipFile
LZMA_IMP_ERR = None LZMA_IMP_ERR = None
if six.PY3: if six.PY3:
@ -527,7 +531,7 @@ class ZipArchive(Archive):
archive = zipfile.ZipFile(_to_native_ascii(path), 'r') archive = zipfile.ZipFile(_to_native_ascii(path), 'r')
checksums = set((info.filename, info.CRC) for info in archive.infolist()) checksums = set((info.filename, info.CRC) for info in archive.infolist())
archive.close() archive.close()
except zipfile.BadZipfile: except BadZipFile:
checksums = set() checksums = set()
return checksums return checksums