Skip to content

Commit ececb6d

Browse files
committed
[ignore] Replace the sanitize function using the two previous small sanitize functions for list and dict.
1 parent 1ed8888 commit ececb6d

File tree

1 file changed

+2
-19
lines changed
  • plugins/module_utils

1 file changed

+2
-19
lines changed

plugins/module_utils/nd.py

+2-19
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,12 @@ def sanitize_list(list_to_sanitize, keys=None, values=None, list_recursive=True,
5858

5959
def sanitize(obj_to_sanitize, keys=None, values=None, recursive=True, remove_none_values=True):
6060
"""Clean up a Python object of type list or dict from specific keys, values and None values if specified"""
61-
if keys is None:
62-
keys = []
63-
if values is None:
64-
values = []
65-
result = deepcopy(obj_to_sanitize)
6661
if isinstance(obj_to_sanitize, dict):
67-
for k, v in obj_to_sanitize.items():
68-
if k in keys:
69-
del result[k]
70-
elif v in values or (v is None and remove_none_values):
71-
del result[k]
72-
elif isinstance(v, dict) and recursive:
73-
result[k] = sanitize(v, keys, values)
74-
elif isinstance(v, list) and recursive:
75-
for index, item in enumerate(v):
76-
if isinstance(item, dict):
77-
result[k][index] = sanitize(item, keys, values)
62+
return sanitize_dict(obj_to_sanitize, keys, values, recursive, remove_none_values)
7863
elif isinstance(obj_to_sanitize, list):
79-
for index, item in enumerate(obj_to_sanitize):
80-
result[index] = sanitize(item, keys, values, recursive, remove_none_values)
64+
return sanitize_list(obj_to_sanitize, keys, values, recursive, recursive, remove_none_values)
8165
else:
8266
raise TypeError("object to sanitize can only be of type list or dict. Got {}".format(type(obj_to_sanitize)))
83-
return result
8467

8568

8669
if PY3:

0 commit comments

Comments
 (0)