Reformat everything.

This commit is contained in:
Felix Fontein
2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View File

@@ -10,6 +10,7 @@ from collections.abc import Mapping
try:
# Introduced with Data Tagging (https://github.com/ansible/ansible/pull/84621):
from ansible.module_utils.datatag import native_type_name as _native_type_name
HAS_NATIVE_TYPE_NAME = True
except ImportError:
HAS_NATIVE_TYPE_NAME = False
@@ -46,16 +47,16 @@ def _ansible_type(data, alias, *, use_native_type: bool = False):
data_type = _atype(data, alias, use_native_type=use_native_type)
if data_type == 'list' and len(data) > 0:
if data_type == "list" and len(data) > 0:
items = [_atype(i, alias, use_native_type=use_native_type) for i in data]
items_type = '|'.join(sorted(set(items)))
items_type = "|".join(sorted(set(items)))
return f"{data_type}[{items_type}]"
if data_type == 'dict' and len(data) > 0:
if data_type == "dict" and len(data) > 0:
keys = [_atype(i, alias, use_native_type=use_native_type) for i in data.keys()]
vals = [_atype(i, alias, use_native_type=use_native_type) for i in data.values()]
keys_type = '|'.join(sorted(set(keys)))
vals_type = '|'.join(sorted(set(vals)))
keys_type = "|".join(sorted(set(keys)))
vals_type = "|".join(sorted(set(vals)))
return f"{data_type}[{keys_type}, {vals_type}]"
return data_type

View File

@@ -13,12 +13,12 @@ from collections.abc import Mapping, Sequence
def _keys_filter_params(data, matching_parameter):
"""test parameters:
* data must be a list of dictionaries. All keys must be strings.
* matching_parameter is member of a list.
* data must be a list of dictionaries. All keys must be strings.
* matching_parameter is member of a list.
"""
mp = matching_parameter
ml = ['equal', 'starts_with', 'ends_with', 'regex']
ml = ["equal", "starts_with", "ends_with", "regex"]
if not isinstance(data, Sequence):
msg = "First argument must be a list. %s is %s"
@@ -43,14 +43,14 @@ def _keys_filter_params(data, matching_parameter):
def _keys_filter_target_str(target, matching_parameter):
"""
Test:
* target is a non-empty string or list.
* If target is list all items are strings.
* target is a string or list with single string if matching_parameter=regex.
Convert target and return:
* tuple of unique target items, or
* tuple with single item, or
* compiled regex if matching_parameter=regex.
Test:
* target is a non-empty string or list.
* If target is list all items are strings.
* target is a string or list with single string if matching_parameter=regex.
Convert target and return:
* tuple of unique target items, or
* tuple with single item, or
* compiled regex if matching_parameter=regex.
"""
if not isinstance(target, Sequence):
@@ -67,7 +67,7 @@ def _keys_filter_target_str(target, matching_parameter):
msg = "The target items must be strings. %s is %s"
raise AnsibleFilterError(msg % (elem, type(elem)))
if matching_parameter == 'regex':
if matching_parameter == "regex":
if isinstance(target, str):
r = target
else:
@@ -82,7 +82,7 @@ def _keys_filter_target_str(target, matching_parameter):
msg = "The target must be a valid regex if matching_parameter=regex. target is %s"
raise AnsibleFilterError(msg % r)
elif isinstance(target, str):
tt = (target, )
tt = (target,)
else:
tt = tuple(set(target))
@@ -91,13 +91,13 @@ def _keys_filter_target_str(target, matching_parameter):
def _keys_filter_target_dict(target, matching_parameter):
"""
Test:
* target is a list of dictionaries with attributes 'after' and 'before'.
* Attributes 'before' must be valid regex if matching_parameter=regex.
* Otherwise, the attributes 'before' must be strings.
Convert target and return:
* iterator that aggregates attributes 'before' and 'after', or
* iterator that aggregates compiled regex of attributes 'before' and 'after' if matching_parameter=regex.
Test:
* target is a list of dictionaries with attributes 'after' and 'before'.
* Attributes 'before' must be valid regex if matching_parameter=regex.
* Otherwise, the attributes 'before' must be strings.
Convert target and return:
* iterator that aggregates attributes 'before' and 'after', or
* iterator that aggregates compiled regex of attributes 'before' and 'after' if matching_parameter=regex.
"""
if not isinstance(target, list):
@@ -112,26 +112,28 @@ def _keys_filter_target_dict(target, matching_parameter):
if not isinstance(elem, Mapping):
msg = "The target items must be dictionaries. %s is %s"
raise AnsibleFilterError(msg % (elem, type(elem)))
if not all(k in elem for k in ('before', 'after')):
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'], str):
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'], str):
raise AnsibleFilterError(msg % (elem["before"], type(elem["before"])))
if not isinstance(elem["after"], str):
msg = "The attributes after must be strings. %s is %s"
raise AnsibleFilterError(msg % (elem['after'], type(elem['after'])))
raise AnsibleFilterError(msg % (elem["after"], type(elem["after"])))
before = [d['before'] for d in target]
after = [d['after'] for d in target]
before = [d["before"] for d in target]
after = [d["after"] for d in target]
if matching_parameter == 'regex':
if matching_parameter == "regex":
try:
tr = map(re.compile, before)
tz = list(zip(tr, after))
except re.error:
msg = ("The attributes before must be valid regex if matching_parameter=regex."
" Not all items are valid regex in: %s")
msg = (
"The attributes before must be valid regex if matching_parameter=regex."
" Not all items are valid regex in: %s"
)
raise AnsibleFilterError(msg % before)
else:
tz = list(zip(before, after))

View File

@@ -13,8 +13,8 @@ from ansible.utils.unsafe_proxy import (
wrap_var as _make_unsafe,
)
_RE_TEMPLATE_CHARS = re.compile('[{}]')
_RE_TEMPLATE_CHARS_BYTES = re.compile(b'[{}]')
_RE_TEMPLATE_CHARS = re.compile("[{}]")
_RE_TEMPLATE_CHARS_BYTES = re.compile(b"[{}]")
def make_unsafe(value):