blob: f8a738f72141bece00689fc2fd04120369c65300 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
def normalize_to_list(value):
"""
Normalize VyOS REST return values to list.
Handles:
dict -> keys
list -> same
str -> [value]
None -> []
"""
if isinstance(value, dict):
return list(value.keys())
if isinstance(value, list):
return value
if isinstance(value, str):
return [value]
return []
def normalize_to_dict(value):
"""
Normalize VyOS REST return values to dict.
list -> {item: {}}
str -> {value: {}}
dict -> same
"""
if isinstance(value, dict):
return value
if isinstance(value, list):
return {v: {} for v in value}
if isinstance(value, str):
return {value: {}}
return {}
|