import pickle
import yaml
import json


def loads(s, format="yaml"):
    """Load from string or bytes

    Parameters
    ----------
    s : str or byte
        String or byte (if binary format as pickle) to load Config from
    format : str
        Which format the Config is written in. ('pickle', 'yaml' or 'json')

    Returns
    -------
    Config
        Loaded Config object

    Raises
    -------
    Exception
        If unknown format

    """
    if format.lower() in ("pickle", ):
        return pickle.loads(s)
    if format.lower() in ("yaml"):
        return yaml.load(s, yaml.Loader)
    if format.lower() in ("json"):
        return json.loads(s)
    raise Exception("Unkown dump format '{}'".format(format))