Skip to content

Commit

Permalink
[PR #6180/f66cc7c9 backport][stable-6] Replace deprecated error with …
Browse files Browse the repository at this point in the history
…BadZipFile (#6216)

Replace deprecated error with BadZipFile (#6180)

* Replace deprecated error with BadZipFile

* Use imported BadZipFile

Co-authored-by: Felix Fontein <[email protected]>

* Add news fragment

* Update new fragment

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit f66cc7c)

Co-authored-by: Hugo van Kemenade <[email protected]>
  • Loading branch information
patchback[bot] and hugovk authored Mar 22, 2023
1 parent 31a1c8e commit ad6c280
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/6180-replace-deprecated-badzipfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "archive - avoid deprecated exception class on Python 3 (https://github.com/ansible-collections/community.general/pull/6180)."
6 changes: 5 additions & 1 deletion plugins/modules/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@
from ansible.module_utils.common.text.converters import to_bytes, to_native
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
if six.PY3:
Expand Down Expand Up @@ -534,7 +538,7 @@ def _get_checksums(self, path):
archive = zipfile.ZipFile(_to_native_ascii(path), 'r')
checksums = set((info.filename, info.CRC) for info in archive.infolist())
archive.close()
except zipfile.BadZipfile:
except BadZipFile:
checksums = set()
return checksums

Expand Down

0 comments on commit ad6c280

Please sign in to comment.