Remove all usage of ansible.module_utils.six from main branch (#10888)

* Get rid of all six.moves imports.

* Get rid of iteritems.

* Get rid of *_type(s) aliases.

* Replace StringIO import.

* Get rid of PY2/PY3 constants.

* Get rid of raise_from.

* Get rid of python_2_unicode_compatible.

* Clean up global six imports.

* Remove all usage of ansible.module_utils.six.

* Linting.

* Fix xml module.

* Docs adjustments.
This commit is contained in:
Felix Fontein 2025-10-11 08:21:57 +02:00 committed by GitHub
commit a8977afb04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
113 changed files with 188 additions and 352 deletions

View file

@ -72,11 +72,8 @@ options:
default: false
notes:
- Can produce C(gzip), C(bzip2), C(lzma), and C(zip) compressed files or archives.
- This module uses C(tarfile), C(zipfile), C(gzip), and C(bz2) packages on the target host to create archives. These are
part of the Python standard library for Python 2 and 3.
requirements:
- Requires C(lzma) (standard library of Python 3) or L(backports.lzma, https://pypi.org/project/backports.lzma/) (Python
2) if using C(xz) format.
- This module uses C(tarfile), C(zipfile), C(gzip), C(bz2), and C(lzma) packages on the target host to create archives. These are
part of the Python standard library.
seealso:
- module: ansible.builtin.unarchive
author:
@ -188,13 +185,11 @@ import shutil
import tarfile
import zipfile
from fnmatch import fnmatch
from sys import version_info
from traceback import format_exc
from zlib import crc32
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 import six
try: # python 3.2+
from zipfile import BadZipFile # type: ignore[attr-defined]
@ -202,22 +197,12 @@ except ImportError: # older python
from zipfile import BadZipfile as BadZipFile
LZMA_IMP_ERR = None
if six.PY3:
try:
import lzma
HAS_LZMA = True
except ImportError:
LZMA_IMP_ERR = format_exc()
HAS_LZMA = False
else:
try:
from backports import lzma
HAS_LZMA = True
except ImportError:
LZMA_IMP_ERR = format_exc()
HAS_LZMA = False
PY27 = version_info[0:2] >= (2, 7)
try:
import lzma
HAS_LZMA = True
except ImportError:
LZMA_IMP_ERR = format_exc()
HAS_LZMA = False
STATE_ABSENT = 'absent'
STATE_ARCHIVED = 'archive'
@ -226,7 +211,7 @@ STATE_INCOMPLETE = 'incomplete'
def common_path(paths):
empty = b'' if paths and isinstance(paths[0], six.binary_type) else ''
empty = b'' if paths and isinstance(paths[0], bytes) else ''
return os.path.join(
os.path.dirname(os.path.commonprefix([os.path.join(os.path.dirname(p), empty) for p in paths])), empty
@ -271,8 +256,7 @@ def _to_native_ascii(s):
return to_native(s, errors='surrogate_or_strict', encoding='ascii')
@six.add_metaclass(abc.ABCMeta)
class Archive(object):
class Archive(object, metaclass=abc.ABCMeta):
def __init__(self, module):
self.module = module
@ -574,16 +558,10 @@ class TarArchive(Archive):
self.module.fail_json(msg="%s is not a valid archive format" % self.format)
def _add(self, path, archive_name):
def py27_filter(tarinfo):
def filter(tarinfo):
return None if matches_exclusion_patterns(tarinfo.name, self.exclusion_patterns) else tarinfo
def py26_filter(path):
return matches_exclusion_patterns(path, self.exclusion_patterns)
if PY27:
self.file.add(path, archive_name, recursive=False, filter=py27_filter)
else:
self.file.add(path, archive_name, recursive=False, exclude=py26_filter)
self.file.add(path, archive_name, recursive=False, filter=filter)
def _get_checksums(self, path):
if HAS_LZMA: