def extract_layout_switch(dic, default=None, do_pop=True):
    """
    Extract the layout and/or view_id value
    from the given dict; if both are present but different,
    a ValueError is raised.

    Futhermore, the "layout" might be got (.getLayout) or set
    (.selectViewTemplate);
    thus, a 3-tuple ('layout_id', do_set, do_get) is returned.
    """
    if do_pop:
        get = dic.pop
    else:
        get = dic.get
    layout = None
    layout_given = False
    set_given = 'set_layout' in dic
    set_layout = get('set_layout', None)
    get_given = 'get_layout' in dic
    get_layout = get('get_layout', None)
    keys = []
    for key in (
        'layout', 'view_id',
        ):
        val = get(key, None)
        if val is not None:
            if layout is None:
                layout = val
            elif val != layout:
                earlier = keys[1:] and tuple(keys) or keys[0]
                raise ValueError('%(key)r: %(val)r conflicts '
                                 '%(earlier)r value %(layout)r!'
                                 % locals())
            keys.append(key)
            layout_given = True
    if layout is None:
        layout = default

    if set_layout is None:
        set_layout = bool(layout)

    return (layout, set_layout, get_layout)