mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -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
|
@ -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'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue