mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 13:04:00 -07:00
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:
parent
8f8a0e1d7c
commit
a8977afb04
113 changed files with 188 additions and 352 deletions
|
|
@ -9,9 +9,9 @@ from __future__ import annotations
|
|||
import copy
|
||||
import json
|
||||
import re
|
||||
from urllib import error as urllib_error
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.module_utils.six.moves.urllib import error as urllib_error
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import csv
|
||||
from io import BytesIO, StringIO
|
||||
from io import StringIO
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.six import PY3
|
||||
|
||||
|
||||
class CustomDialectFailureError(Exception):
|
||||
|
|
@ -58,10 +57,7 @@ def read_csv(data, dialect, fieldnames=None):
|
|||
if data.startswith(BOM):
|
||||
data = data[len(BOM):]
|
||||
|
||||
if PY3:
|
||||
fake_fh = StringIO(data)
|
||||
else:
|
||||
fake_fh = BytesIO(data)
|
||||
fake_fh = StringIO(data)
|
||||
|
||||
reader = csv.DictReader(fake_fh, fieldnames=fieldnames, dialect=dialect)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
# (TODO: remove AnsibleModule from next line!)
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib # noqa: F401, pylint: disable=unused-import
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
from os.path import expanduser
|
||||
from uuid import UUID
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ from __future__ import annotations
|
|||
|
||||
from ansible.module_utils.basic import missing_required_lib
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.six import integer_types, string_types
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
|
|
@ -144,7 +143,7 @@ def vars_to_variables(vars, module):
|
|||
# transform old vars to new variables structure
|
||||
variables = list()
|
||||
for item, value in vars.items():
|
||||
if isinstance(value, (string_types, integer_types, float)):
|
||||
if isinstance(value, (str, int, float)):
|
||||
variables.append(
|
||||
{
|
||||
"name": item,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
import re
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def _create_regex_group_complement(s):
|
||||
|
|
@ -70,7 +69,7 @@ class HomebrewValidate(object):
|
|||
- os.path.sep
|
||||
"""
|
||||
|
||||
if isinstance(path, string_types):
|
||||
if isinstance(path, str):
|
||||
return not cls.INVALID_PATH_REGEX.search(path)
|
||||
|
||||
try:
|
||||
|
|
@ -98,7 +97,7 @@ class HomebrewValidate(object):
|
|||
return True
|
||||
|
||||
return isinstance(
|
||||
brew_path, string_types
|
||||
brew_path, str
|
||||
) and not cls.INVALID_BREW_PATH_REGEX.search(brew_path)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -109,7 +108,7 @@ class HomebrewValidate(object):
|
|||
return True
|
||||
|
||||
return isinstance(
|
||||
package, string_types
|
||||
package, str
|
||||
) and not cls.INVALID_PACKAGE_REGEX.search(package)
|
||||
|
||||
|
||||
|
|
@ -126,7 +125,7 @@ def parse_brew_path(module):
|
|||
if not HomebrewValidate.valid_path(path):
|
||||
module.fail_json(msg="Invalid path: {0}".format(path))
|
||||
|
||||
if isinstance(path, string_types):
|
||||
if isinstance(path, str):
|
||||
paths = path.split(":")
|
||||
elif isinstance(path, list):
|
||||
paths = path
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ from __future__ import annotations
|
|||
import json
|
||||
import traceback
|
||||
import copy
|
||||
from urllib.parse import urlencode, quote
|
||||
from urllib.error import HTTPError
|
||||
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode, quote
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
from ansible.module_utils.common.text.converters import to_native, to_text
|
||||
|
||||
URL_REALM_INFO = "{url}/realms/{realm}"
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@ import uuid
|
|||
|
||||
import re
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||
from ansible.module_utils.six import PY3
|
||||
from ansible.module_utils.six.moves.urllib.parse import quote
|
||||
from ansible.module_utils.urls import fetch_url, HAS_GSSAPI
|
||||
from ansible.module_utils.basic import env_fallback, AnsibleFallbackNotFound
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
def _env_then_dns_fallback(*args, **kwargs):
|
||||
|
|
@ -135,14 +134,7 @@ class IPAClient(object):
|
|||
except Exception as e:
|
||||
self._fail('post %s' % method, to_native(e))
|
||||
|
||||
if PY3:
|
||||
charset = resp.headers.get_content_charset('latin-1')
|
||||
else:
|
||||
response_charset = resp.headers.getparam('charset')
|
||||
if response_charset:
|
||||
charset = response_charset
|
||||
else:
|
||||
charset = 'latin-1'
|
||||
charset = resp.headers.get_content_charset('latin-1')
|
||||
resp = json.loads(to_text(resp.read(), encoding=charset))
|
||||
err = resp.get('error')
|
||||
if err is not None:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import os
|
|||
import hmac
|
||||
import re
|
||||
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from urllib.parse import urlparse
|
||||
|
||||
try:
|
||||
from hashlib import sha1
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
|
||||
import http.client as http_client
|
||||
import os
|
||||
import socket
|
||||
import ssl
|
||||
import json
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from ansible.module_utils.urls import generic_urlparse
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.module_utils.six.moves import http_client
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
# httplib/http.client connection using unix domain socket
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from urllib.parse import urlencode
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.basic import json
|
||||
import ansible.module_utils.six.moves.urllib.error as urllib_error
|
||||
import urllib.error as urllib_error
|
||||
|
||||
|
||||
class Response(object):
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import json
|
|||
import time
|
||||
import uuid
|
||||
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
||||
|
|
@ -167,7 +166,7 @@ def list_pritunl_organizations(
|
|||
else:
|
||||
if not any(
|
||||
filter_val != org[filter_key]
|
||||
for filter_key, filter_val in iteritems(filters)
|
||||
for filter_key, filter_val in filters.items()
|
||||
):
|
||||
orgs.append(org)
|
||||
|
||||
|
|
@ -198,7 +197,7 @@ def list_pritunl_users(
|
|||
else:
|
||||
if not any(
|
||||
filter_val != user[filter_key]
|
||||
for filter_key, filter_val in iteritems(filters)
|
||||
for filter_key, filter_val in filters.items()
|
||||
):
|
||||
users.append(user)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ from __future__ import annotations
|
|||
import json
|
||||
import os
|
||||
import uuid
|
||||
from urllib.error import URLError, HTTPError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
|
||||
|
||||
GET_HEADERS = {'accept': 'application/json'}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import abc
|
|||
import collections
|
||||
import json
|
||||
import traceback
|
||||
from collections.abc import Mapping
|
||||
|
||||
HPE_ONEVIEW_IMP_ERR = None
|
||||
try:
|
||||
|
|
@ -24,10 +25,8 @@ except ImportError:
|
|||
HPE_ONEVIEW_IMP_ERR = traceback.format_exc()
|
||||
HAS_HPE_ONEVIEW = False
|
||||
|
||||
from ansible.module_utils import six
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.six.moves.collections_abc import Mapping
|
||||
|
||||
|
||||
def transform_list_to_dict(list_):
|
||||
|
|
@ -128,7 +127,7 @@ class OneViewModuleException(Exception):
|
|||
self.msg = None
|
||||
self.oneview_response = None
|
||||
|
||||
if isinstance(data, six.string_types):
|
||||
if isinstance(data, str):
|
||||
self.msg = data
|
||||
else:
|
||||
self.oneview_response = data
|
||||
|
|
@ -178,8 +177,7 @@ class OneViewModuleResourceNotFound(OneViewModuleException):
|
|||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class OneViewModuleBase(object):
|
||||
class OneViewModuleBase(object, metaclass=abc.ABCMeta):
|
||||
MSG_CREATED = 'Resource created successfully.'
|
||||
MSG_UPDATED = 'Resource updated successfully.'
|
||||
MSG_DELETED = 'Resource deleted successfully.'
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from __future__ import annotations
|
|||
import time
|
||||
import ssl
|
||||
from os import environ
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
|
|
@ -263,7 +262,7 @@ class OpenNebulaModule:
|
|||
self.cast_template(template[key])
|
||||
elif isinstance(value, list):
|
||||
template[key] = ', '.join(value)
|
||||
elif not isinstance(value, string_types):
|
||||
elif not isinstance(value, str):
|
||||
template[key] = str(value)
|
||||
|
||||
def requires_template_update(self, current, desired):
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ except ImportError:
|
|||
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
__version__ = "1.6.0-dev"
|
||||
|
||||
|
|
@ -820,7 +819,7 @@ def is_attr_assigned_default(default_attribute_values, attr, assigned_value):
|
|||
# this is to ensure forward compatibility when the API returns new keys that are not known during
|
||||
# the time when the module author provided default values for the attribute
|
||||
keys = {}
|
||||
for k, v in iteritems(assigned_value.items()):
|
||||
for k, v in assigned_value.items().items():
|
||||
if k in default_val_for_attr:
|
||||
keys[k] = v
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible.module_utils.six import raise_from
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ class PackageRequirement:
|
|||
return req.name, req
|
||||
|
||||
except Exception as e:
|
||||
raise_from(ValueError("Invalid package specification for '{0}': {1}".format(name, e)), e)
|
||||
raise ValueError("Invalid package specification for '{0}': {1}".format(name, e)) from e
|
||||
|
||||
def matches_version(self, version):
|
||||
"""
|
||||
|
|
@ -70,4 +68,4 @@ class PackageRequirement:
|
|||
return ver in self.requirement.specifier
|
||||
|
||||
except InvalidVersion as e:
|
||||
raise_from(ValueError("Invalid version '{0}': {1}".format(version, e)))
|
||||
raise ValueError("Invalid version '{0}': {1}".format(version, e)) from e
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import http.client as http_client
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
|
|
@ -13,10 +14,8 @@ from ansible.module_utils.urls import open_url
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.module_utils.six import text_type
|
||||
from ansible.module_utils.six.moves import http_client
|
||||
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from urllib.error import URLError, HTTPError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
GET_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
|
||||
POST_HEADERS = {'content-type': 'application/json', 'accept': 'application/json',
|
||||
|
|
@ -378,7 +377,7 @@ class RedfishUtils(object):
|
|||
def write_buffer(body, line):
|
||||
# Adds to the multipart body based on the provided data type
|
||||
# At this time there is only support for strings, dictionaries, and bytes (default)
|
||||
if isinstance(line, text_type):
|
||||
if isinstance(line, str):
|
||||
body.append(to_bytes(line, encoding='utf-8'))
|
||||
elif isinstance(line, dict):
|
||||
body.append(to_bytes(json.dumps(line), encoding='utf-8'))
|
||||
|
|
|
|||
|
|
@ -29,11 +29,9 @@ from stringprep import (
|
|||
)
|
||||
from unicodedata import normalize
|
||||
|
||||
from ansible.module_utils.six import text_type
|
||||
|
||||
|
||||
def is_unicode_str(string):
|
||||
return True if isinstance(string, text_type) else False
|
||||
return True if isinstance(string, str) else False
|
||||
|
||||
|
||||
def mapping_profile(string):
|
||||
|
|
@ -156,9 +154,8 @@ def saslprep(string):
|
|||
# RFC4013: "The algorithm assumes all strings are
|
||||
# comprised of characters from the Unicode [Unicode] character set."
|
||||
# Validate the string is a Unicode string
|
||||
# (text_type is the string type if PY3 and unicode otherwise):
|
||||
if not is_unicode_str(string):
|
||||
raise TypeError('input must be of type %s, not %s' % (text_type, type(string)))
|
||||
raise TypeError('input must be of type str, not %s' % type(string))
|
||||
|
||||
# RFC4013: 2.1. Mapping.
|
||||
string = mapping_profile(string)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import sys
|
|||
import datetime
|
||||
import time
|
||||
import traceback
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.module_utils.basic import env_fallback, missing_required_lib
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.datetime import (
|
||||
now,
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@ import re
|
|||
import time
|
||||
import tarfile
|
||||
import os
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
from ansible.module_utils.urls import fetch_file
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlunparse
|
||||
|
||||
|
||||
class WdcRedfishUtils(RedfishUtils):
|
||||
"""Extension to RedfishUtils to support WDC enclosures."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue