def get_collection(collection, key, default=None):
    """
    Retrieves a key from a collection, replacing None and unset values with the
    default value.  If default is None, an empty dictionary will be the
    default.

    If key is a list, it is treated as a key traversal.

    This is useful for configs, where the configured value is often None,
    but should be interpreted as an empty collection.
    """
    if default is None:
        default = {}
    if isinstance(key, list):
        out = collection
        for k in key:
            out = get_collection(out, k)
    else:
        out = collection.get(key, None)
    return out if out is not None else default