Return a list of valid kwargs to function func
503472
def get_kwarg_names(func):
    
    sig = inspect.signature(func)
    kwonlyargs = [p.name for p in sig.parameters.values()
                  if p.default is not p.empty]
    return kwonlyargs
1147866
def get_func_result_cachekey(func_, args_=tuple(), kwargs_={}):
    
    import utool as ut
    # Rectify partials and whatnot
    true_args = args_
    true_kwargs = kwargs_
    true_func = func_
    if isinstance(func_, partial):
        true_func = func_.func
        if func_.args is not None:
            true_args = tuple(list(func_.args) + list(args_))
        if func_.keywords is not None:
            true_kwargs.update(func_.keywords)

    if ut.is_method(true_func):
        method = true_func
        true_func = method.im_func
        self = method.im_self
        true_args = tuple([self] + list(true_args))

    # Build up cachekey
    funcname = ut.get_funcname(true_func)
    kwdefaults = ut.get_kwdefaults(true_func, parse_source=False)
    #kwdefaults = ut.get_kwdefaults(true_func, parse_source=True)
    argnames   = ut.get_argnames(true_func)
    key_argx = None
    key_kwds = None
    func = true_func  # NOQA
    args = true_args  # NOQA
    kwargs = true_kwargs  # NOQA
    args_key = ut.get_cfgstr_from_args(true_func, true_args, true_kwargs,
                                       key_argx, key_kwds, kwdefaults,
                                       argnames)
    cachekey = funcname + '(' + args_key + ')'
    return cachekey
75709
def argument(*args, **kwargs):
    
    def decorator(f):
        if not hasattr(f, '_arguments'):
            f._arguments = []
        if not hasattr(f, '_argnames'):
            f._argnames = []
        f._arguments.append((args, kwargs))
        f._argnames.append(_get_dest(*args, **kwargs))
        return f
    return decorator
816944
def _get_params(func, *args, **kwargs):
    
    params = dict(zip(func.func_code.co_varnames[:len(args)], args))
    if func.func_defaults:
        params.update(dict(zip(
            func.func_code.co_varnames[-len(func.func_defaults):],
            func.func_defaults)))
    params.update(kwargs)

    return params
602633
def ensure_unicode_args(function):
    '''
    
    '''
    @wraps(function)
    def wrapped(*args, **kwargs):
        if six.PY2:
            return function(
                *salt.utils.data.decode_list(args),
                **salt.utils.data.decode_dict(kwargs)
            )
        else:
            return function(*args, **kwargs)
    return wrapped
287511
def _get_defaults(func):
    """"""
    try:
        code = func.__code__
    except AttributeError:
        # Some built-in functions don't have __code__, __defaults__, etc.
        return {}
    pos_count = code.co_argcount
    arg_names = code.co_varnames
    arg_names = arg_names[:pos_count]
    defaults = func.__defaults__ or ()
    kwdefaults = func.__kwdefaults__
    res = dict(kwdefaults) if kwdefaults else {}
    pos_offset = pos_count - len(defaults)
    for name, value in zip(arg_names[pos_offset:], defaults):
        assert name not in res
        res[name] = value
    return res
844293
def split_kwargs_by_func(kwargs, func):
    ""
    args = func_args(func)
    func_kwargs = {a:kwargs.pop(a) for a in args if a in kwargs}
    return func_kwargs, kwargs
1007057
def make_function_arguments(args,
                            kwonly,
                            varargs,
                            varkwargs,
                            defaults,
                            kw_defaults,
                            annotations):
    
    return ast.arguments(
        args=[ast.arg(arg=a, annotation=annotations.get(a)) for a in args],
        kwonlyargs=[
            ast.arg(arg=a, annotation=annotations.get(a)) for a in kwonly
        ],
        defaults=defaults,
        kw_defaults=list(map(kw_defaults.get, kwonly)),
        vararg=None if varargs is None else ast.arg(
            arg=varargs, annotation=annotations.get(varargs),
        ),
        kwarg=None if varkwargs is None else ast.arg(
            arg=varkwargs, annotation=annotations.get(varkwargs)
        ),
    )
81649
def _getFuncArgs(func):
  
  """
  code = func.func_code
  Defaults = func.func_defaults

  nargs = code.co_argcount
  ArgNames = code.co_varnames[:nargs]

  Args = OrderedDict()
  argCount = len(ArgNames)
  defCount = len(Defaults) if Defaults else 0
  diff = argCount - defCount

  for i in range(0, diff):
    Args[ArgNames[i]] = {}

  for i in range(diff, argCount):
    Args[ArgNames[i]] = {'default': Defaults[i - diff]}

  return Args
914234
def _functionFabric(func_name, argList, oargList, password):
    """"""

    def functionHandler(self, *args, **kwargs):
        call_args = {}

        for (key, value) in oargList.items():
            call_args[key] = value

        for i, arg in enumerate(argList):
            if i < len(args):
                call_args[arg] = args[i]

        for (key, value) in kwargs.items():
            call_args[key] = value

        return _callFunc(self, func_name, password, call_args)

    functionHandler.__name__ = str(func_name)
    return functionHandler
555730
def _get_clean_parameters(kwargs):
        
        return dict((k, v) for k, v in kwargs.items() if v is not None)
505297
def get_kwargs(kwargs):
    
    return {
        key: value for key, value in six.iteritems(kwargs)
        if key != 'self'
    }
1007567
def kwargs(self):
    
    return {k: v for k, v in self._kwargs.items() if k not in self._INTERNAL_FIELDS}
1020928
def function_parameters(function):
    
    if not callable(function):
        raise TypeError(
            'function_parameters(function=%s) you must pass a function' % (
                function
            )
        )
    def wrapper(*args, **kwargs):
        if function.__doc__ is not None:
            if len(function.__doc__) > 3 and len(
                    args) + len(kwargs) + len(
                        function.__defaults__ if function.__defaults__ else ''
                        ) >= len(getParaList(function)):
                paras_index = [p for p in getParaList(
                    function) if p not in kwargs.keys()]
                for content in [i.split('))')[0
                ] for i in function.__doc__.replace(
                    ' ', '').split('((') if ':' in i and i.split(
                        ':')[0] in paras_index or i.split(':'
                        )[0] in kwargs.keys()]:
                    con = content.split(':')
                    if con[0] in kwargs.keys() or len(args) > paras_index.index(con[0]):
                        # To avoid default parameters
                        try:
                            if not isinstance(eval(con[1]), type):
                                raise TypeError()
                        except Exception:
                            raise TypeError(
                                "function_parameters(%s(%s=%s)) " % (
                                    getsourcefile(function) + 
                                    ' ' + function.__name__,
                                    con[0], con[1]
                                ) + "wrong type given in __doc__" 
                            )
                        received_arg = kwargs.get(con[0])
                        if not received_arg and con[0] in paras_index:
                            # to avoid kwarg when it's arg
                            received_arg = args[paras_index.index(con[0])]
                        if type(received_arg) != eval(con[1]):
                            raise TypeError(
                                "%s(%s=%s) requires type %s" % (
                                    getsourcefile(function) + 
                                    ' ' + function.__name__,
                                    con[0], type(received_arg),
                                    eval(con[1])
                                )
                            )
        return function(*args, **kwargs)
    return wrapper
1128164
def get_kwargs(self):
        """"""
        return {k: v for k, v in vars(self).items() if k not in self._ignored}
528753
def params(self):
        """"""
        ret = {}
        for rd in self.decorators:
            args = rd.args
            kwargs = rd.kwargs
            if param in rd:
                is_required =  kwargs.get('required', 'default' not in kwargs)
                ret[args[0]] = {'required': is_required, 'other_names': args[1:], 'options': kwargs}

        return ret
1363112
def execute(self, func, *args, **kwargs):
        
        return [
            func(item, *args, **kwargs) for item in self.to_lst()
        ]