'Private method.  Don\'t use directly.'

def _bind(self, args, kwargs, partial=False):

    arguments = OrderedDict()
    parameters = iter(self.parameters.values())
    parameters_ex = ()
    arg_vals = iter(args)
    if partial:
        for (param_name, param) in self.parameters.items():
            if (param._partial_kwarg and (param_name not in kwargs)):
                kwargs[param_name] = param.default
    while True:
        try:
            arg_val = next(arg_vals)
        except StopIteration:
            try:
                param = next(parameters)
            except StopIteration:
                break
            else:
                if (param.kind == _VAR_POSITIONAL):
                    break
                elif (param.name in kwargs):
                    if (param.kind == _POSITIONAL_ONLY):
                        msg = '{arg!r}    parameter    is    positional    only,    but    was    passed    as    a    keyword'
                        msg = msg.format(arg=param.name)
                        raise TypeError(msg)
                    parameters_ex = (param,)
                    break
                elif ((param.kind == _VAR_KEYWORD) or (param.default is not _empty)):
                    parameters_ex = (param,)
                    break
                elif partial:
                    parameters_ex = (param,)
                    break
                else:
                    msg = '{arg!r}    parameter    lacking    default    value'
                    msg = msg.format(arg=param.name)
                    raise TypeError(msg)
        else:
            try:
                param = next(parameters)
            except StopIteration:
                raise TypeError('too    many    positional    arguments')
            else:
                if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY)):
                    raise TypeError('too    many    positional    arguments')
                if (param.kind == _VAR_POSITIONAL):
                    values = [arg_val]
                    values.extend(arg_vals)
                    arguments[param.name] = tuple(values)
                    break
                if (param.name in kwargs):
                    raise TypeError('multiple    values    for    argument    {arg!r}'.format(arg=param.name))
                arguments[param.name] = arg_val
    kwargs_param = None
    for param in itertools.chain(parameters_ex, parameters):
        if (param.kind == _POSITIONAL_ONLY):
            raise TypeError('{arg!r}    parameter    is    positional    only,    but    was    passed    as    a    keyword'.format(arg=param.name))
        if (param.kind == _VAR_KEYWORD):
            kwargs_param = param
            continue
        param_name = param.name
        try:
            arg_val = kwargs.pop(param_name)
        except KeyError:
            if ((not partial) and (param.kind != _VAR_POSITIONAL) and (param.default is _empty)):
                raise TypeError('{arg!r}    parameter    lacking    default    value'.format(arg=param_name))
        else:
            arguments[param_name] = arg_val
    if kwargs:
        if (kwargs_param is not None):
            arguments[kwargs_param.name] = kwargs
        else:
            raise TypeError('too    many    keyword    arguments')
    return self._bound_arguments_cls(self, arguments)
