project/util/iter.py

18 lines
541 B
Python

def json_path(obj: dict, key: str):
"""Query a nested dict with a dot-separated path"""
if not type(obj) is dict:
return None
if "." not in key:
return obj[key]
child_key = key.split(".")
if child_key[0] not in obj:
return None
return json_path(obj[child_key[0]], ".".join(child_key[1:]))
def combinate(settings: dict, entry:dict)-> bool:
"""combine all settings {<key>: <expected>} with entry using AND"""
result = True
for key, value in settings.items():
result = result and json_path(entry, key) == value
return result