diff options
| -rw-r--r-- | python/vyos/util.py | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/python/vyos/util.py b/python/vyos/util.py index d27a8a3e7..4cc25764b 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -672,3 +672,17 @@ def find_device_file(device):                  return os.path.join(root, basename)      return None + +def vyos_dict_search(dict, path): +    """ Traverse Python dictionary (dict) delimited by dot (.). +    Return value of key if found, None otherwise. + +    This is faster implementation then jmespath.search('foo.bar', dict)""" +    parts = path.split('.') +    inside = parts[:-1] +    if not inside: +        return dict[path] +    c = dict +    for p in parts[:-1]: +        c = c.get(p, {}) +    return c.get(parts[-1], None) | 
