def poparg(kwargs, **argdef):
    """
    Get an argument, with a default, from a dict of **kwargs.

    Use it like this::

        def fn(**kwargs):
            foo = poparg(kwargs, foo=17)

    Now `foo` is the value of the foo argument to fn, with a default of 17. The
    keyword argument can be any keyword you like, its name will be the key
    plucked from `kwargs`.

    `kwargs` has the argument removed, so that it can be passed on to
    another function.

    Arguments:
        kwargs (dict): the keyword arguments to the calling function.

    Returns:
        The value of the argument, defaulted to the value passed to the
        keyword argument.

    """
    assert len(argdef) == 1
    name, value = argdef.popitem()
    return kwargs.pop(name, value)