# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# def restore(flat):
#     return json.decode(_json.dumps(flat), keys=True)


import os
import pickle
import json
import sacred.optional as opt
from sacred.serializer import flatten, restore
    ".json": Handler(
        lambda fp: restore(json.load(fp)),
        lambda obj, fp: json.dump(flatten(obj), fp, sort_keys=True, indent=2),
        "",
    ),
    ".pickle": Handler(pickle.load, pickle.dump, "b"),
}

yaml_extensions = (".yaml", ".yml")
if opt.has_yaml:

    def load_yaml(filename):
        return opt.yaml.load(filename, Loader=opt.yaml.FullLoader)

    yaml_handler = Handler(load_yaml, opt.yaml.dump, "")

    for extension in yaml_extensions:
        HANDLER_BY_EXT[extension] = yaml_handler


def get_handler(filename):
    _, extension = os.path.splitext(filename)
    if extension in yaml_extensions and not opt.has_yaml:
        raise KeyError(
            'Configuration file "{}" cannot be loaded as '
            "you do not have PyYAML installed.".format(filename)
        )
    try:
        return HANDLER_BY_EXT[extension]
    except KeyError:

# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# def restore(flat):
#     return json.decode(_json.dumps(flat), keys=True)


# Path: sacred/config/config_files.py
import os
import pickle
import json
import sacred.optional as opt
from sacred.serializer import flatten, restore

    ".json": Handler(
        lambda fp: restore(json.load(fp)),
        lambda obj, fp: json.dump(flatten(obj), fp, sort_keys=True, indent=2),
        "",
    ),
    ".pickle": Handler(pickle.load, pickle.dump, "b"),
}

yaml_extensions = (".yaml", ".yml")
if opt.has_yaml:

    def load_yaml(filename):
        return opt.yaml.load(filename, Loader=opt.yaml.FullLoader)

    yaml_handler = Handler(load_yaml, opt.yaml.dump, "")

    for extension in yaml_extensions:
        HANDLER_BY_EXT[extension] = yaml_handler


def get_handler(filename):
    _, extension = os.path.splitext(filename)
    if extension in yaml_extensions and not opt.has_yaml:
        raise KeyError(
            'Configuration file "{}" cannot be loaded as '
            "you do not have PyYAML installed.".format(filename)
        )
    try:
        return HANDLER_BY_EXT[extension]
    except KeyError:

        raise ValueError(