def eval_extract()

in fog-updater/src/fog_update.py [0:0]


def eval_extract(code):
    """
    Eval `code` and return a map of variables and their values.

    `code` should be valid Python code.
    Only the builtins `list` and `set` are provided.

    Note: this executes arbitrary Python code.
    Because of the limited builtins list this should be reasonably safe.
    Still only use this with known valid code!
    """

    # Allow `list` and `set`, so `list(set(a+b+c))` works.
    globs = {"__builtins__": {"list": list, "set": set, "sorted": sorted}}
    exec(code, globs)
    globs.pop("__builtins__")
    return globs