from functools import wraps


def lowercase_kwargs(*kwarg_names, **defaults):
    """
    Decorator for converting given kwargs that are list of strings to lowercase, and optionally appending a
    default value.
    """
    default_append = defaults.get('default_append', None)

    def wrapper(func):
        """The actual decorator that we'll return"""
        @wraps(func)
        def wrapped(*args, **kwargs):
            """The wrapped function"""
            for kwarg in kwarg_names:
                if kwarg in kwargs:
                    kwargs[kwarg] = kwargs[kwarg] or []
                    kwargs[kwarg] = [ob.lower() for ob in kwargs[kwarg]]
                    if default_append is not None:
                        kwargs[kwarg].append(default_append)
            return func(*args, **kwargs)
        return wrapped
    return wrapper