|
4 | 4 | from typing import Mapping, List, Union |
5 | 5 | from .utils.jmspath.parsers import jmspath_value_parser, jmspath_refkey_parser |
6 | 6 | from .utils.data.parsers import exclude_filter, get_values |
| 7 | +from .utils.refkey.utils import keys_cleaner, keys_values_zipper |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def extract_values_from_output(value: Mapping, path: Mapping, exclude: List) -> Union[Mapping, List, int, str, bool]: |
@@ -91,59 +92,3 @@ def associate_key_of_my_value(paths: Mapping, wanted_value: List) -> List: |
91 | 92 |
|
92 | 93 | return final_list |
93 | 94 |
|
94 | | - |
95 | | -def keys_cleaner(wanted_reference_keys: Mapping) -> list: |
96 | | - """ |
97 | | - Get every required reference key from output. |
98 | | -
|
99 | | - Args: |
100 | | - wanted_reference_keys: {'10.1.0.0': {'address_family': {'ipv4': ... |
101 | | -
|
102 | | - Return: |
103 | | - ['10.1.0.0', '10.2.0.0', '10.64.207.255', '7.7.7.7'] |
104 | | -
|
105 | | - Example: |
106 | | - >>> from runner import keys_cleaner |
107 | | - >>> wanted_reference_keys = {'10.1.0.0': {'address_family': 'ipv4'}} |
108 | | - >>> keys_cleaner(wanted_reference_keys) |
109 | | - ['10.1.0.0', '10.2.0.0', '10.64.207.255', '7.7.7.7'] |
110 | | - """ |
111 | | - if isinstance(wanted_reference_keys, list): |
112 | | - return wanted_reference_keys |
113 | | - |
114 | | - elif isinstance(wanted_reference_keys, dict): |
115 | | - my_keys_list = list() |
116 | | - |
117 | | - for key in wanted_reference_keys.keys(): |
118 | | - my_keys_list.append(key) |
119 | | - |
120 | | - return my_keys_list |
121 | | - |
122 | | - |
123 | | -def keys_values_zipper(list_of_reference_keys: List, wanted_value_with_key: List) -> List: |
124 | | - """ |
125 | | - Build dictionary zipping keys with relative values. |
126 | | -
|
127 | | - Args: |
128 | | - list_of_reference_keys: ['10.1.0.0', '10.2.0.0', '10.64.207.255', '7.7.7.7'] |
129 | | - wanted_value_with_key: [{'is_enabled': True, 'is_up': False}, ... |
130 | | -
|
131 | | - Return: |
132 | | - [{'10.1.0.0': {'is_enabled': True, 'is_up': False}}, , ... |
133 | | -
|
134 | | - Example: |
135 | | - >>> from runner import keys_values_zipper |
136 | | - >>> list_of_reference_keys = ['10.1.0.0'] |
137 | | - >>> wanted_value_with_key = [{'is_enabled': True, 'is_up': False}] |
138 | | - >>> keys_values_zipper(list_of_reference_keys, wanted_value_with_key) |
139 | | - [{'10.1.0.0': {'is_enabled': True, 'is_up': False}}] |
140 | | - """ |
141 | | - final_result = list() |
142 | | - |
143 | | - if len(list_of_reference_keys) != len(wanted_value_with_key): |
144 | | - raise ValueError("Keys len != from Values len") |
145 | | - |
146 | | - for my_index, my_key in enumerate(list_of_reference_keys): |
147 | | - final_result.append({my_key: wanted_value_with_key[my_index]}) |
148 | | - |
149 | | - return final_result |
0 commit comments