def anon()

in tsdb/_tools/anonymize.py [0:0]


def anon(path, it):
    result = {}
    for k, v in it.items():
        new_path = k if path == "" else path + "." + k
        if isinstance(v, dict):
            result[k] = anon(new_path, v)
            continue
        strategy = strategies.get(new_path)
        if not strategy:
            raise KeyError(f"Unknown key [{new_path}] with value [{v}]")
        if strategy == "drop":
            continue
        if isinstance(it, list):
            result[k] = [strategy(item) for item in v]
            continue
        result[k] = strategy(v)
    return result