import pickle


def _safe_restore(data, rep):
    """ Safely restore pickled data, resorting to representation on fail """
    try:
        return pickle.loads(data)
    except Exception:
        return rep