def first_kwonly_arg(name):
def decorate(wrapped):<EOL><INDENT>if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>arg_names, varargs, _, defaults = inspect.getargspec(wrapped)<EOL><DEDENT>else:<EOL><INDENT>arg_names, varargs, _, defaults = inspect.getfullargspec(wrapped)[:<NUM_LIT:4>]<EOL><DEDENT>if not defaults:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>first_default_index = len(arg_names) - len(defaults)<EOL>if name is FIRST_DEFAULT_ARG:<EOL><INDENT>first_kwonly_index = first_default_index<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>first_kwonly_index = arg_names.index(name)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ValueError("<STR_LIT>" % (<EOL>getattr(wrapped, '<STR_LIT>', '<STR_LIT:?>'), name))<EOL><DEDENT><DEDENT>if first_kwonly_index < first_default_index:<EOL><INDENT>raise ValueError("<STR_LIT>" % (name,))<EOL><DEDENT>kwonly_defaults = defaults[-(len(arg_names)-first_kwonly_index):]<EOL>kwonly_args = tuple(zip(arg_names[first_kwonly_index:], kwonly_defaults))<EOL>required_kwonly_args = frozenset(arg for arg, default in kwonly_args if default is KWONLY_REQUIRED)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>if required_kwonly_args:<EOL><INDENT>missing_kwonly_args = required_kwonly_args.difference(kwargs.keys())<EOL>if missing_kwonly_args:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>getattr(wrapped, '<STR_LIT>', '<STR_LIT:?>'), len(missing_kwonly_args),<EOL>'<STR_LIT:U+002CU+0020>'.join(sorted(missing_kwonly_args))))<EOL><DEDENT><DEDENT>if len(args) > first_kwonly_index:<EOL><INDENT>if varargs is None:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>getattr(wrapped, '<STR_LIT>', '<STR_LIT:?>'), first_kwonly_index, len(args)))<EOL><DEDENT>kwonly_args_from_kwargs = tuple(kwargs.pop(arg, default) for arg, default in kwonly_args)<EOL>args = args[:first_kwonly_index] + kwonly_args_from_kwargs + args[first_kwonly_index:]<EOL><DEDENT>return wrapped(*args, **kwargs)<EOL><DEDENT>return update_wrapper(wrapper, wrapped)<EOL><DEDENT>return decorate<EOL>
Emulates keyword-only arguments under python2. Works with both python2 and python3.
    With this decorator you can convert all or some of the default arguments of your function
    into kwonly arguments. Use ``KWONLY_REQUIRED`` as the default value of required kwonly args.

    :param name: The name of the first default argument to be treated as a keyword-only argument. This default
    argument along with all default arguments that follow this one will be treated as keyword only arguments.

    You can also pass here the ``FIRST_DEFAULT_ARG`` constant in order to select the first default argument. This
    way you turn all default arguments into keyword-only arguments. As a shortcut you can use the
    ``@kwonly_defaults`` decorator (without any parameters) instead of ``@first_kwonly_arg(FIRST_DEFAULT_ARG)``.

        >>> from kwonly_args import first_kwonly_arg, KWONLY_REQUIRED, FIRST_DEFAULT_ARG, kwonly_defaults
        >>>
        >>> # this decoration converts the ``d1`` and ``d2`` default args into kwonly args
        >>> @first_kwonly_arg('d1')
        >>> def func(a0, a1, d0='d0', d1='d1', d2='d2', *args, **kwargs):
        >>>     print(a0, a1, d0, d1, d2, args, kwargs)
        >>>
        >>> func(0, 1, 2, 3, 4)
        0 1 2 d1 d2 (3, 4) {}
        >>>
        >>> func(0, 1, 2, 3, 4, d2='my_param')
        0 1 2 d1 my_param (3, 4) {}
        >>>
        >>> # d0 is an optional deyword argument, d1 is required
        >>> def func(d0='d0', d1=KWONLY_REQUIRED):
        >>>     print(d0, d1)
        >>>
        >>> # The ``FIRST_DEFAULT_ARG`` constant automatically selects the first default argument so it
        >>> # turns all default arguments into keyword-only ones. Both d0 and d1 are keyword-only arguments.
        >>> @first_kwonly_arg(FIRST_DEFAULT_ARG)
        >>> def func(a0, a1, d0='d0', d1='d1'):
        >>>     print(a0, a1, d0, d1)
        >>>
        >>> # ``@kwonly_defaults`` is a shortcut for the ``@first_kwonly_arg(FIRST_DEFAULT_ARG)``
        >>> # in the previous example. This example has the same effect as the previous one.
        >>> @kwonly_defaults
        >>> def func(a0, a1, d0='d0', d1='d1'):
        >>>     print(a0, a1, d0, d1)