summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-23 18:39:36 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-23 18:41:51 +0100
commitfbc1ce06eede24d34b339008f41dda70a0cb0ec7 (patch)
tree953fb3a67afe99813d082c9ddc5ddcd10ba8c3b8 /python/vyos
parent9f6f3197578792397f225e01b0379107f1c7ea32 (diff)
downloadvyos-1x-fbc1ce06eede24d34b339008f41dda70a0cb0ec7.tar.gz
vyos-1x-fbc1ce06eede24d34b339008f41dda70a0cb0ec7.zip
vyos.util: dict_search() should not throw exception when inputs are None
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/util.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index e4de56cdb..e2f4b8fc4 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -630,18 +630,21 @@ def find_device_file(device):
return None
-def dict_search(path, dict):
- """ Traverse Python dictionary (dict) delimited by dot (.).
+def dict_search(path, my_dict):
+ """ Traverse Python dictionary (my_dict) delimited by dot (.).
Return value of key if found, None otherwise.
- This is faster implementation then jmespath.search('foo.bar', dict)"""
+ This is faster implementation then jmespath.search('foo.bar', my_dict)"""
+ if not isinstance(my_dict, dict) or not path:
+ return None
+
parts = path.split('.')
inside = parts[:-1]
if not inside:
- if path not in dict:
+ if path not in my_dict:
return None
- return dict[path]
- c = dict
+ return my_dict[path]
+ c = my_dict
for p in parts[:-1]:
c = c.get(p, {})
return c.get(parts[-1], None)