mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 04:24:00 -07:00
[stable-10] Avoid six in plugin code (#10873) (#10877)
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.15) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.10) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.5) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.15) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.10) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.5) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
Avoid six in plugin code (#10873)
Avoid six in plugin code.
(cherry picked from commit 6cd4665412
)
This commit is contained in:
parent
4ab8f79eae
commit
171a028ef8
37 changed files with 80 additions and 130 deletions
2
changelogs/fragments/10873-six.yml
Normal file
2
changelogs/fragments/10873-six.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "Avoid usage of deprecated ``ansible.module_utils.six`` in all code that does not have to support Python 2 (https://github.com/ansible-collections/community.general/pull/10873)."
|
|
@ -59,8 +59,8 @@ notes:
|
|||
- This plugin ignores the C(become_user) supplied and uses C(pmrun)'s own configuration to select the user.
|
||||
"""
|
||||
|
||||
from shlex import quote as shlex_quote
|
||||
from ansible.plugins.become import BecomeBase
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
|
||||
|
||||
class BecomeModule(BecomeBase):
|
||||
|
|
6
plugins/cache/pickle.py
vendored
6
plugins/cache/pickle.py
vendored
|
@ -48,7 +48,6 @@ try:
|
|||
except ImportError:
|
||||
import pickle
|
||||
|
||||
from ansible.module_utils.six import PY3
|
||||
from ansible.plugins.cache import BaseFileCacheModule
|
||||
|
||||
|
||||
|
@ -61,10 +60,7 @@ class CacheModule(BaseFileCacheModule):
|
|||
def _load(self, filepath):
|
||||
# Pickle is a binary format
|
||||
with open(filepath, 'rb') as f:
|
||||
if PY3:
|
||||
return pickle.load(f, encoding='bytes')
|
||||
else:
|
||||
return pickle.load(f)
|
||||
return pickle.load(f, encoding='bytes')
|
||||
|
||||
def _dump(self, value, filepath):
|
||||
with open(filepath, 'wb') as f:
|
||||
|
|
|
@ -27,7 +27,6 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
from ansible.module_utils.six import binary_type, text_type
|
||||
from collections.abc import MutableMapping, MutableSequence
|
||||
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
|
@ -236,7 +235,7 @@ class CallbackModule(CallbackModule_default):
|
|||
|
||||
# Remove empty attributes (list, dict, str)
|
||||
for attr in result.copy():
|
||||
if isinstance(result[attr], (MutableSequence, MutableMapping, binary_type, text_type)):
|
||||
if isinstance(result[attr], (MutableSequence, MutableMapping, bytes, str)):
|
||||
if not result[attr]:
|
||||
del result[attr]
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ from contextlib import closing
|
|||
from os.path import basename
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleRuntimeError
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
try:
|
||||
|
@ -312,9 +311,7 @@ class CallbackModule(CallbackBase):
|
|||
self.disabled = False
|
||||
|
||||
if ELASTIC_LIBRARY_IMPORT_ERROR:
|
||||
raise_from(
|
||||
AnsibleError('The `elastic-apm` must be installed to use this plugin'),
|
||||
ELASTIC_LIBRARY_IMPORT_ERROR)
|
||||
raise AnsibleError('The `elastic-apm` must be installed to use this plugin') from ELASTIC_LIBRARY_IMPORT_ERROR
|
||||
|
||||
self.tasks_data = OrderedDict()
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ options:
|
|||
type: string
|
||||
"""
|
||||
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
|
|
@ -137,14 +137,12 @@ import json
|
|||
import os
|
||||
import socket
|
||||
import uuid
|
||||
from time import time_ns
|
||||
|
||||
from collections import OrderedDict
|
||||
from os.path import basename
|
||||
from time import time_ns
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
try:
|
||||
|
@ -499,9 +497,9 @@ class CallbackModule(CallbackBase):
|
|||
self.otel_exporter_otlp_traces_protocol = None
|
||||
|
||||
if OTEL_LIBRARY_IMPORT_ERROR:
|
||||
raise_from(
|
||||
AnsibleError('The `opentelemetry-api`, `opentelemetry-exporter-otlp` or `opentelemetry-sdk` must be installed to use this plugin'),
|
||||
OTEL_LIBRARY_IMPORT_ERROR)
|
||||
raise AnsibleError(
|
||||
'The `opentelemetry-api`, `opentelemetry-exporter-otlp` or `opentelemetry-sdk` must be installed to use this plugin'
|
||||
) from OTEL_LIBRARY_IMPORT_ERROR
|
||||
|
||||
self.tasks_data = OrderedDict()
|
||||
|
||||
|
|
|
@ -75,11 +75,11 @@ import os
|
|||
import os.path
|
||||
import subprocess
|
||||
import traceback
|
||||
from shlex import quote as shlex_quote
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.basic import is_executable
|
||||
from ansible.module_utils.common.process import get_bin_path
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||
from ansible.utils.display import Display
|
||||
|
|
|
@ -38,9 +38,9 @@ import os
|
|||
import os.path
|
||||
import subprocess
|
||||
import traceback
|
||||
from shlex import quote as shlex_quote
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils.common.process import get_bin_path
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||
|
|
|
@ -31,9 +31,9 @@ import os
|
|||
import os.path
|
||||
import subprocess
|
||||
import traceback
|
||||
from shlex import quote as shlex_quote
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils.common.process import get_bin_path
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||
|
|
|
@ -45,10 +45,10 @@ _value:
|
|||
"""
|
||||
|
||||
|
||||
from io import StringIO
|
||||
from configparser import ConfigParser
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||
|
||||
|
||||
class IniParser(ConfigParser):
|
||||
|
@ -73,7 +73,7 @@ class IniParser(ConfigParser):
|
|||
def from_ini(obj):
|
||||
''' Read the given string as INI file and return a dict '''
|
||||
|
||||
if not isinstance(obj, string_types):
|
||||
if not isinstance(obj, str):
|
||||
raise AnsibleFilterError(f'from_ini requires a str, got {type(obj)}')
|
||||
|
||||
parser = IniParser()
|
||||
|
|
|
@ -196,7 +196,6 @@ _value:
|
|||
"""
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six import string_types
|
||||
from collections.abc import Mapping, Sequence
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
@ -257,7 +256,7 @@ def lists_mergeby(*terms, **kwargs):
|
|||
|
||||
index = terms[-1]
|
||||
|
||||
if not isinstance(index, string_types):
|
||||
if not isinstance(index, str):
|
||||
msg = ("First argument after the lists for community.general.lists_mergeby must be string. "
|
||||
"%s is %s")
|
||||
raise AnsibleFilterError(msg % (index, type(index)))
|
||||
|
|
|
@ -45,14 +45,13 @@ import re
|
|||
from random import Random, SystemRandom
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def random_mac(value, seed=None):
|
||||
''' takes string prefix, and return it completed with random bytes
|
||||
to get a complete 6 bytes MAC address '''
|
||||
|
||||
if not isinstance(value, string_types):
|
||||
if not isinstance(value, str):
|
||||
raise AnsibleFilterError('Invalid value type (%s) for random_mac (%s)' %
|
||||
(type(value), value))
|
||||
|
||||
|
|
|
@ -49,11 +49,10 @@ _value:
|
|||
type: string
|
||||
"""
|
||||
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from collections.abc import Mapping
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||
from configparser import ConfigParser
|
||||
from io import StringIO
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
|
||||
class IniParser(ConfigParser):
|
||||
|
|
|
@ -120,7 +120,6 @@ except ImportError:
|
|||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
class TypeValidationError(AnsibleFilterError):
|
||||
|
@ -131,7 +130,7 @@ class TypeValidationError(AnsibleFilterError):
|
|||
expected: Description of expected type
|
||||
"""
|
||||
def __init__(self, obj, expected):
|
||||
type_name = "string" if isinstance(obj, string_types) else type(obj).__name__
|
||||
type_name = "string" if isinstance(obj, str) else type(obj).__name__
|
||||
super().__init__(f"Expected {expected}, got a {type_name}")
|
||||
|
||||
|
||||
|
@ -160,7 +159,7 @@ def _validate_list_param(param, param_name, ensure_strings=True):
|
|||
|
||||
if ensure_strings:
|
||||
for item in param:
|
||||
if not isinstance(item, string_types):
|
||||
if not isinstance(item, str):
|
||||
# Maintain original error message format
|
||||
if param_name == "column_order":
|
||||
error_msg = "a string for column name"
|
||||
|
@ -186,7 +185,7 @@ def _match_key(item_dict, lookup_key):
|
|||
return lookup_key
|
||||
|
||||
# Try boolean conversion for 'true'/'false' strings
|
||||
if isinstance(lookup_key, string_types):
|
||||
if isinstance(lookup_key, str):
|
||||
if lookup_key.lower() == 'true' and True in item_dict:
|
||||
return True
|
||||
if lookup_key.lower() == 'false' and False in item_dict:
|
||||
|
@ -338,11 +337,11 @@ def to_prettytable(data, *args, **kwargs):
|
|||
# Validate column_alignments keys and values
|
||||
for key, value in column_alignments.items():
|
||||
# Check that keys are strings
|
||||
if not isinstance(key, string_types):
|
||||
if not isinstance(key, str):
|
||||
raise TypeValidationError(key, "a string for column_alignments key")
|
||||
|
||||
# Check that values are strings
|
||||
if not isinstance(value, string_types):
|
||||
if not isinstance(value, str):
|
||||
raise TypeValidationError(value, "a string for column_alignments value")
|
||||
|
||||
# Check that values are valid alignments
|
||||
|
@ -394,7 +393,7 @@ def to_prettytable(data, *args, **kwargs):
|
|||
row.append(item.get(matched_key, ""))
|
||||
else:
|
||||
# Try case-insensitive lookup as last resort
|
||||
lower_col = col.lower() if isinstance(col, string_types) else str(col).lower()
|
||||
lower_col = col.lower() if isinstance(col, str) else str(col).lower()
|
||||
if lower_col in reverse_key_map:
|
||||
row.append(item.get(reverse_key_map[lower_col], ""))
|
||||
else:
|
||||
|
|
|
@ -49,7 +49,6 @@ _value:
|
|||
from unicodedata import normalize
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six import text_type
|
||||
|
||||
try:
|
||||
from ansible.errors import AnsibleTypeError
|
||||
|
@ -69,7 +68,7 @@ def unicode_normalize(data, form='NFC'):
|
|||
A normalized unicode string of the specified 'form'.
|
||||
"""
|
||||
|
||||
if not isinstance(data, text_type):
|
||||
if not isinstance(data, str):
|
||||
raise AnsibleTypeError("%s is not a valid input type" % type(data))
|
||||
|
||||
if form not in ('NFC', 'NFD', 'NFKC', 'NFKD'):
|
||||
|
|
|
@ -131,7 +131,6 @@ import socket
|
|||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, to_safe_group_name
|
||||
from ansible.module_utils.six import text_type
|
||||
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
|
@ -260,7 +259,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
self.cobbler = xmlrpc_client.Server(self.cobbler_url, allow_none=True)
|
||||
self.token = None
|
||||
if self.get_option('user') is not None:
|
||||
self.token = self.cobbler.login(text_type(self.get_option('user')), text_type(self.get_option('password')))
|
||||
self.token = self.cobbler.login(str(self.get_option('user')), str(self.get_option('password')))
|
||||
|
||||
self.cache_key = self.get_cache_key(path)
|
||||
self.use_cache = cache and self.get_option('cache')
|
||||
|
|
|
@ -96,11 +96,11 @@ compose:
|
|||
"""
|
||||
|
||||
import json
|
||||
from urllib.error import HTTPError
|
||||
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
|
|
|
@ -171,12 +171,12 @@ import json
|
|||
import re
|
||||
import time
|
||||
import os
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||
from ansible.module_utils.common.text.converters import to_native, to_text
|
||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible_collections.community.general.plugins.module_utils.lxd import LXDClient, LXDClientException
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
|
@ -1094,9 +1094,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
Returns:
|
||||
None"""
|
||||
if IPADDRESS_IMPORT_ERROR:
|
||||
raise_from(
|
||||
AnsibleError('another_library must be installed to use this plugin'),
|
||||
IPADDRESS_IMPORT_ERROR)
|
||||
raise AnsibleError('another_library must be installed to use this plugin') from IPADDRESS_IMPORT_ERROR
|
||||
|
||||
super(InventoryModule, self).parse(inventory, loader, path, cache=False)
|
||||
# Read the inventory YAML file
|
||||
|
|
|
@ -62,13 +62,13 @@ groups:
|
|||
|
||||
import json
|
||||
from sys import version as python_version
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.six.moves.urllib.parse import urljoin
|
||||
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
|
|
|
@ -224,13 +224,12 @@ want_proxmox_nodes_ansible_host: true
|
|||
|
||||
import itertools
|
||||
import re
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.module_utils.common._collections_compat import MutableMapping
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.utils.display import Display
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
@ -498,7 +497,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
out_val[k] = v
|
||||
value = out_val
|
||||
|
||||
if config not in plaintext_configs and isinstance(value, string_types) \
|
||||
if config not in plaintext_configs and isinstance(value, str) \
|
||||
and all("=" in v for v in value.split(",")):
|
||||
# split off strings with commas to a dict
|
||||
# skip over any keys that cannot be processed
|
||||
|
|
|
@ -128,9 +128,8 @@ from ansible_collections.community.general.plugins.module_utils.scaleway import
|
|||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.six import raise_from
|
||||
|
||||
import ansible.module_utils.six.moves.urllib.parse as urllib_parse
|
||||
import urllib.parse as urllib_parse
|
||||
|
||||
|
||||
def _fetch_information(token, url):
|
||||
|
@ -334,7 +333,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
|
||||
def parse(self, inventory, loader, path, cache=True):
|
||||
if YAML_IMPORT_ERROR:
|
||||
raise_from(AnsibleError('PyYAML is probably missing'), YAML_IMPORT_ERROR)
|
||||
raise AnsibleError('PyYAML is probably missing') from YAML_IMPORT_ERROR
|
||||
super(InventoryModule, self).parse(inventory, loader, path)
|
||||
self._read_config_data(path=path)
|
||||
|
||||
|
|
|
@ -112,7 +112,8 @@ _raw:
|
|||
type: dict
|
||||
"""
|
||||
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleAssertionError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
|
|
@ -122,7 +122,6 @@ _list:
|
|||
|
||||
from ansible.errors import AnsibleLookupError
|
||||
from collections.abc import Mapping, Sequence
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.release import __version__ as ansible_version
|
||||
from ansible.template import Templar
|
||||
|
@ -225,7 +224,7 @@ class LookupModule(LookupBase):
|
|||
raise AnsibleLookupError(
|
||||
f'The variable {k!r} appears more than once')
|
||||
vars_so_far.add(k)
|
||||
if isinstance(v, string_types):
|
||||
if isinstance(v, str):
|
||||
data.append((k, v, None))
|
||||
elif isinstance(v, (Sequence, Mapping)):
|
||||
data.append((k, None, v))
|
||||
|
|
|
@ -37,7 +37,6 @@ _raw:
|
|||
type: list
|
||||
"""
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||
|
||||
|
@ -65,7 +64,7 @@ class LookupModule(LookupBase):
|
|||
# ignore undefined items
|
||||
break
|
||||
|
||||
if isinstance(term, string_types):
|
||||
if isinstance(term, str):
|
||||
# convert a variable to a list
|
||||
try:
|
||||
term2 = listify_lookup_plugin_terms(term, templar=self._templar)
|
||||
|
|
|
@ -75,8 +75,9 @@ except ImportError:
|
|||
|
||||
import time
|
||||
import json
|
||||
from urllib.error import HTTPError
|
||||
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.display import Display
|
||||
|
|
|
@ -63,16 +63,18 @@ RETURN = '''
|
|||
the same environment variable(s), the last one returned by the Manifold API will take precedence.
|
||||
type: dict
|
||||
'''
|
||||
|
||||
import json
|
||||
import sys
|
||||
from traceback import format_exception
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils import six
|
||||
from ansible.utils.display import Display
|
||||
from traceback import format_exception
|
||||
import json
|
||||
import sys
|
||||
|
||||
display = Display()
|
||||
|
||||
|
|
|
@ -86,7 +86,6 @@ from ansible.plugins.lookup import LookupBase
|
|||
from ansible.errors import AnsibleLookupError, AnsibleOptionsError
|
||||
from ansible.module_utils.common.process import get_bin_path
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||
from ansible.module_utils.six import with_metaclass
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.onepassword import OnePasswordConfig
|
||||
|
||||
|
@ -99,7 +98,7 @@ def _lower_if_possible(value):
|
|||
return value
|
||||
|
||||
|
||||
class OnePassCLIBase(with_metaclass(abc.ABCMeta, object)):
|
||||
class OnePassCLIBase(object, metaclass=abc.ABCMeta):
|
||||
bin = "op"
|
||||
|
||||
def __init__(
|
||||
|
|
|
@ -66,7 +66,6 @@ EXAMPLES = r"""
|
|||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.display import Display
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import raise_from
|
||||
|
||||
try:
|
||||
from pam.revbits_ansible.server import SecretServer
|
||||
|
@ -87,10 +86,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
if ANOTHER_LIBRARY_IMPORT_ERROR:
|
||||
raise_from(
|
||||
AnsibleError('revbits_ansible must be installed to use this plugin'),
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR
|
||||
)
|
||||
raise AnsibleError('revbits_ansible must be installed to use this plugin') from ANOTHER_LIBRARY_IMPORT_ERROR
|
||||
self.set_options(var_options=variables, direct=kwargs)
|
||||
secret_server = LookupModule.Client(
|
||||
{
|
||||
|
|
|
@ -258,7 +258,6 @@ EXAMPLES = r"""
|
|||
import abc
|
||||
import os
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.module_utils import six
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
|
@ -289,8 +288,7 @@ except ImportError:
|
|||
display = Display()
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class TSSClient(object):
|
||||
class TSSClient(object, metaclass=abc.ABCMeta):
|
||||
def __init__(self):
|
||||
self._client = None
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ __metaclass__ = type
|
|||
import re
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six import string_types
|
||||
from collections.abc import Mapping, Sequence
|
||||
|
||||
|
||||
|
@ -32,7 +31,7 @@ def _keys_filter_params(data, matching_parameter):
|
|||
raise AnsibleFilterError(msg % (elem, type(elem)))
|
||||
|
||||
for elem in data:
|
||||
if not all(isinstance(item, string_types) for item in elem.keys()):
|
||||
if not all(isinstance(item, str) for item in elem.keys()):
|
||||
msg = "Top level keys must be strings. keys: %s"
|
||||
raise AnsibleFilterError(msg % elem.keys())
|
||||
|
||||
|
@ -65,12 +64,12 @@ def _keys_filter_target_str(target, matching_parameter):
|
|||
|
||||
if isinstance(target, list):
|
||||
for elem in target:
|
||||
if not isinstance(elem, string_types):
|
||||
if not isinstance(elem, str):
|
||||
msg = "The target items must be strings. %s is %s"
|
||||
raise AnsibleFilterError(msg % (elem, type(elem)))
|
||||
|
||||
if matching_parameter == 'regex':
|
||||
if isinstance(target, string_types):
|
||||
if isinstance(target, str):
|
||||
r = target
|
||||
else:
|
||||
if len(target) > 1:
|
||||
|
@ -83,7 +82,7 @@ def _keys_filter_target_str(target, matching_parameter):
|
|||
except re.error:
|
||||
msg = "The target must be a valid regex if matching_parameter=regex. target is %s"
|
||||
raise AnsibleFilterError(msg % r)
|
||||
elif isinstance(target, string_types):
|
||||
elif isinstance(target, str):
|
||||
tt = (target, )
|
||||
else:
|
||||
tt = tuple(set(target))
|
||||
|
@ -117,10 +116,10 @@ def _keys_filter_target_dict(target, matching_parameter):
|
|||
if not all(k in elem for k in ('before', 'after')):
|
||||
msg = "All dictionaries in target must include attributes: after, before."
|
||||
raise AnsibleFilterError(msg)
|
||||
if not isinstance(elem['before'], string_types):
|
||||
if not isinstance(elem['before'], str):
|
||||
msg = "The attributes before must be strings. %s is %s"
|
||||
raise AnsibleFilterError(msg % (elem['before'], type(elem['before'])))
|
||||
if not isinstance(elem['after'], string_types):
|
||||
if not isinstance(elem['after'], str):
|
||||
msg = "The attributes after must be strings. %s is %s"
|
||||
raise AnsibleFilterError(msg % (elem['after'], type(elem['after'])))
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ __metaclass__ = type
|
|||
|
||||
import re
|
||||
|
||||
from ansible.module_utils.six import binary_type, text_type
|
||||
from collections.abc import Mapping, Set
|
||||
from ansible.module_utils.common.collections import is_sequence
|
||||
from ansible.utils.unsafe_proxy import (
|
||||
|
@ -29,11 +28,11 @@ def make_unsafe(value):
|
|||
return set(make_unsafe(elt) for elt in value)
|
||||
elif is_sequence(value):
|
||||
return type(value)(make_unsafe(elt) for elt in value)
|
||||
elif isinstance(value, binary_type):
|
||||
elif isinstance(value, bytes):
|
||||
if _RE_TEMPLATE_CHARS_BYTES.search(value):
|
||||
value = _make_unsafe(value)
|
||||
return value
|
||||
elif isinstance(value, text_type):
|
||||
elif isinstance(value, str):
|
||||
if _RE_TEMPLATE_CHARS.search(value):
|
||||
value = _make_unsafe(value)
|
||||
return value
|
||||
|
|
|
@ -223,8 +223,9 @@ _value:
|
|||
type: bool
|
||||
'''
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.six.moves.collections_abc import Sequence
|
||||
from ansible_collections.community.general.plugins.plugin_utils.ansible_type import _ansible_type
|
||||
|
||||
|
||||
|
|
|
@ -5,16 +5,6 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import raise_from
|
||||
|
||||
try:
|
||||
from fqdn import FQDN
|
||||
except ImportError as imp_exc:
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR = imp_exc
|
||||
else:
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR = None
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
name: fqdn_valid
|
||||
|
@ -74,6 +64,15 @@ _value:
|
|||
type: bool
|
||||
'''
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
try:
|
||||
from fqdn import FQDN
|
||||
except ImportError as imp_exc:
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR = imp_exc
|
||||
else:
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR = None
|
||||
|
||||
|
||||
def fqdn_valid(name, min_labels=1, allow_underscores=False):
|
||||
"""
|
||||
|
@ -83,10 +82,7 @@ def fqdn_valid(name, min_labels=1, allow_underscores=False):
|
|||
"""
|
||||
|
||||
if ANOTHER_LIBRARY_IMPORT_ERROR:
|
||||
raise_from(
|
||||
AnsibleError('Python package fqdn must be installed to use this test.'),
|
||||
ANOTHER_LIBRARY_IMPORT_ERROR
|
||||
)
|
||||
raise AnsibleError('Python package fqdn must be installed to use this test.') from ANOTHER_LIBRARY_IMPORT_ERROR
|
||||
|
||||
fobj = FQDN(name, min_labels=min_labels, allow_underscores=allow_underscores)
|
||||
return (fobj.is_valid)
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def callback_results_extractor(outputs_results):
|
||||
results = []
|
||||
|
@ -18,7 +16,7 @@ def callback_results_extractor(outputs_results):
|
|||
line = "line_%s" % (i + 1)
|
||||
test_line = stdout_lines[i] if i < len(stdout_lines) else None
|
||||
expected_lines = expected_output[i] if i < len(expected_output) else None
|
||||
if not isinstance(expected_lines, string_types) and expected_lines is not None:
|
||||
if not isinstance(expected_lines, str) and expected_lines is not None:
|
||||
if test_line not in expected_lines:
|
||||
differences.append({
|
||||
'line': {
|
||||
|
|
|
@ -1,20 +1,3 @@
|
|||
plugins/cache/pickle.py pylint:ansible-bad-import-from
|
||||
plugins/callback/dense.py pylint:ansible-bad-import-from
|
||||
plugins/callback/elastic.py pylint:ansible-bad-import-from
|
||||
plugins/callback/opentelemetry.py pylint:ansible-bad-import-from
|
||||
plugins/filter/from_ini.py pylint:ansible-bad-import-from
|
||||
plugins/filter/lists_mergeby.py pylint:ansible-bad-import-from
|
||||
plugins/filter/random_mac.py pylint:ansible-bad-import-from
|
||||
plugins/filter/to_prettytable.py pylint:ansible-bad-import-from
|
||||
plugins/filter/unicode_normalize.py pylint:ansible-bad-import-from
|
||||
plugins/inventory/cobbler.py pylint:ansible-bad-import-from
|
||||
plugins/inventory/lxd.py pylint:ansible-bad-import-from
|
||||
plugins/inventory/proxmox.py pylint:ansible-bad-import-from
|
||||
plugins/inventory/scaleway.py pylint:ansible-bad-import-from
|
||||
plugins/lookup/dependent.py pylint:ansible-bad-import-from
|
||||
plugins/lookup/flattened.py pylint:ansible-bad-import-from
|
||||
plugins/lookup/onepassword.py pylint:ansible-bad-import-from
|
||||
plugins/lookup/revbitspss.py pylint:ansible-bad-import-from
|
||||
plugins/module_utils/csv.py pylint:ansible-bad-import-from
|
||||
plugins/module_utils/gitlab.py pylint:ansible-bad-import-from
|
||||
plugins/module_utils/homebrew.py pylint:ansible-bad-import-from
|
||||
|
@ -57,10 +40,6 @@ plugins/modules/xfconf.py validate-modules:return-syntax-error
|
|||
plugins/modules/xml.py pylint:ansible-bad-import-from
|
||||
plugins/modules/zpool_facts.py pylint:ansible-bad-import-from
|
||||
plugins/modules/zypper_repository.py pylint:ansible-bad-import-from
|
||||
plugins/plugin_utils/keys_filter.py pylint:ansible-bad-import-from
|
||||
plugins/plugin_utils/unsafe.py pylint:ansible-bad-import-from
|
||||
plugins/test/fqdn_valid.py pylint:ansible-bad-import-from
|
||||
tests/integration/targets/callback/filter_plugins/helper.py pylint:ansible-bad-import-from
|
||||
tests/unit/plugins/module_utils/identity/keycloak/test_keycloak_connect.py pylint:ansible-bad-import-from
|
||||
tests/unit/plugins/module_utils/net_tools/pritunl/test_api.py pylint:ansible-bad-import-from
|
||||
tests/unit/plugins/modules/conftest.py pylint:ansible-bad-import-from
|
||||
|
|
|
@ -9,12 +9,12 @@ from ansible_collections.community.internal_test_tools.tests.unit.compat import
|
|||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import patch, call
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.urls import ConnectionError, SSLValidationError
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
||||
from ansible.module_utils import six
|
||||
from ansible.plugins.loader import lookup_loader
|
||||
from ansible_collections.community.general.plugins.lookup.manifold import ManifoldApiClient, ApiError
|
||||
import json
|
||||
import os
|
||||
from urllib.error import HTTPError, URLError
|
||||
|
||||
|
||||
API_FIXTURES = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue