def _extract_move_args(dic, default=None, do_pop=True):
    """
    Only for _tree.clone_tree for now, and not yet generalized;
    might become replaced, removed or renamed!

    Take a (usually: **kwargs) dict and extract (by default: pop)
    the keys move_children, move_limit and move_limit_each

    Return a 3-tuple (move_children, move_limit, move_limit_each);
    move_children defaults to True, if at least one of the other keys
    were contained.

    Arguments:

    dic - the dictionary
    default - default value for move_limit* keys
    do_pop - whether to pop the keys from the dict.

    >>> dic = {'move_limit': 1, 'other_option': 42}
    >>> _extract_move_args(dic)
    (True, 1, None)
    >>> dic
    {'other_option': 42}
    >>> dic = {'other_option': 42}
    >>> _extract_move_args(dic, 3)
    (False, 3, 3)
    """
    if do_pop:
        get = dic.pop
    else:
        get = dic.get
    res = [None]
    has_other = False

    for otherkey in ('move_limit', 'move_limit_each'):
        if otherkey in dic:
            val = get(otherkey)
            has_other = True
        else:
            val = get(otherkey, default)
        res.append(val)
    res[0] = get('move_children', has_other)
    return tuple(res)