def freeze(obj):
    """Transform tree of dict and list in read-only
    data structure.
    dict instances are transformed to FrozenDict, lists
    in FrozenList.
    """
    if isinstance(obj, collections.Mapping):
        return FrozenDict({freeze(k): freeze(v) for k, v in six.iteritems(obj)})
    elif isinstance(obj, list):
        return FrozenList([freeze(e) for e in obj])
    else:
        return obj
Transform tree of dict and list in read-only
    data structure.
    dict instances are transformed to FrozenDict, lists
    in FrozenList.