Inspect and potentially mutate the given handler's arguments.
		
		The args list and kw dictionary may be freely modified, though invalid arguments to the handler will fail.
516454
def mutate(self, context, handler, args, kw):
		
		def cast(arg, val):
			if arg not in annotations:
				return
			
			cast = annotations[key]
			
			try:
				val = cast(val)
			except (ValueError, TypeError) as e:
				parts = list(e.args)
				parts[0] = parts[0] + " processing argument '{}'".format(arg)
				e.args = tuple(parts)
				raise
			
			return val
			
		annotations = getattr(handler.__func__ if hasattr(handler, '__func__') else handler, '__annotations__', None)
		if not annotations:
			return
		
		argspec = getfullargspec(handler)
		arglist = list(argspec.args)
		
		if ismethod(handler):
			del arglist[0]
		
		for i, value in enumerate(list(args)):
			key = arglist[i]
			if key in annotations:
				args[i] = cast(key, value)
		
		# Convert keyword arguments
		for key, value in list(items(kw)):
			if key in annotations:
				kw[key] = cast(key, value)
156311
def _fetch_arguments(handler, method):
    """"""

    if method.__name__ == 'get':
        arguments = {}
        for key, value in six.iteritems(handler.request.arguments):
            # Tornado supports comma-separated lists of values in
            # parameters. We're undoing that here, and if a list
            # is expected the _validate method can handle it.
            if isinstance(value, list):
                arguments[key] = ','.join(value)
            else:
                arguments[key] = value
    else:  # post, put, patch, delete?
        arguments = handler.get_post_arguments()

    return arguments
296284
def _visit_handlers(handlers, visitor, prefix, suffixes):
    

    results = []
    for handler in handlers:
        for suffix in suffixes:
            func = getattr(handler, '{}_{}'.format(prefix, suffix).lower(), None)
            if func:
                results.append(visitor(suffix, func))

    return results
588155
def _add_argument(obj, arg):
        
        argparse_options = {name: value for name, value in arg.options.items() if name in ARGPARSE_SUPPORTED_KWARGS}
        if arg.options_list:
            scrubbed_options_list = []
            for item in arg.options_list:

                if isinstance(item, Deprecated):
                    # don't add expired options to the parser
                    if item.expired():
                        continue

                    class _DeprecatedOption(str):
                        def __new__(cls, *args, **kwargs):
                            instance = str.__new__(cls, *args, **kwargs)
                            return instance

                    option = _DeprecatedOption(item.target)
                    setattr(option, 'deprecate_info', item)
                    item = option
                scrubbed_options_list.append(item)
            return obj.add_argument(*scrubbed_options_list, **argparse_options)

        if 'required' in argparse_options:
            del argparse_options['required']
        if 'metavar' not in argparse_options:
            argparse_options['metavar'] = '<{}>'.format(argparse_options['dest'].upper())
        return obj.add_argument(**argparse_options)
414534
def mutates(f):
    '''
    '''
    @wraps(f)
    def wrapper(self, *args, **kwargs):
        if self.read_only:
            raise ReadOnlyException()
        self.next_generation()
        return f(self, *args, **kwargs)
    return wrapper
536813
def curargs(self):
        
        #This is where we update the arguments to new dictionary versions when the code
        #is updated with new features etc. so that the older, serialized sessions don't
        #break.
        if (self.active not in self._version_check or 
            self.group not in self._version_check[self.active]):
            if ("version" not in self.args[self.active][self.group] or
                self.args[self.active][self.group]["version"] < self._template_args["version"]):
                for key in self._template_args:
                    if key not in self.args[self.active][self.group]:
                        self.args[self.active][self.group][key] = self._template_args[key]
                self.args[self.active][self.group]["version"] = self._template_args["version"]

            if self.active not in self._version_check:
                self._version_check[self.active] = [self.group]
            else:
                self._version_check[self.active].append(self.group)

        return self.args[self.active][self.group]
689780
def describe_arguments(func):
    

    argspec = inspect.getargspec(func)
    # we should probably raise an exception somewhere if func includes **kwargs
    if argspec.defaults:
        positional_args = argspec.args[:-len(argspec.defaults)]
        keyword_names = argspec.args[-len(argspec.defaults):]
        for arg, default in zip(keyword_names, argspec.defaults):
            yield ('--{}'.format(arg),), {'default': default}
    else:
        positional_args = argspec.args

    for arg in positional_args:
        yield (arg,), {}
    if argspec.varargs:
        yield (argspec.varargs,), {'nargs': '*'}
730391
def takes_arg(obj, arg: str) -> bool:
    
    if inspect.isclass(obj):
        signature = inspect.signature(obj.__init__)
    elif inspect.ismethod(obj) or inspect.isfunction(obj):
        signature = inspect.signature(obj)
    else:
        raise ConfigurationError(f"object {obj} is not callable")
    return arg in signature.parameters
1177879
def exec_argparse_funckw(func, globals_=None, defaults={}, **kwargs):
    
    import utool as ut
    funckw = ut.get_func_kwargs(func)
    funckw.update(defaults)
    parsekw = ut.argparse_dict(funckw, **kwargs)
    if globals_:
        globals_.update(parsekw)
    return parsekw
439338
def get_valid_kwargs(func, potential_kwargs):
    
    kwargs = {}
    for name in get_kwarg_names(func):
        with suppress(KeyError):
            kwargs[name] = potential_kwargs[name]
    return kwargs
370460
def execute(self, handler, arg):
        
        return lib.zconfig_execute(self._as_parameter_, handler, arg)
1303532
def takes_kwargs(obj) -> bool:
    
    if inspect.isclass(obj):
        signature = inspect.signature(obj.__init__)
    elif inspect.ismethod(obj) or inspect.isfunction(obj):
        signature = inspect.signature(obj)
    else:
        raise ConfigurationError(f"object {obj} is not callable")
    return bool(any([p.kind == inspect.Parameter.VAR_KEYWORD  # type: ignore
                     for p in signature.parameters.values()]))
115289
def filter_subcommand_args(func, options):
    
    kwargs = {}
    argspec = inspect.getargspec(func)
    for arg in argspec.args:
        if arg in options:
            kwargs.update({arg: getattr(options, arg)})
    return kwargs
470038
def _replace_services_in_args(self, args):
        
        _check_type('args', args, list)

        new_args = []
        for arg in args:
            if isinstance(arg, list):
                new_args.append(self._replace_services_in_args(arg))
            elif isinstance(arg, dict):
                new_args.append(self._replace_services_in_kwargs(arg))
            elif isinstance(arg, string_types):
                new_args.append(self._replace_service(arg))
            else:
                new_args.append(arg)
        return new_args
571916
def addHandler(self, handler):
        
        self._handlers.append(handler)
        self.inner.addHandler(handler)
141824
def _clone_args(self):
        
        keys = list(self.keys)
        kw = {}
        if self.allow_any or self.extras:
            kw['allow_extra'] = list(self.extras)
            if self.allow_any:
                kw['allow_extra'].append('*')
            kw['allow_extra_trafaret'] = self.extras_trafaret
        if self.ignore_any or self.ignore:
            kw['ignore_extra'] = list(self.ignore)
            if self.ignore_any:
                kw['ignore_any'].append('*')
        return keys, kw
1120332
def override_args(**kwargs):
  

  override_kwargs = kwargs

  def custom_getter(getter, *args, **kwargs):
    """Custom getter with certain named arguments overridden.

    Args:
      getter: Underlying variable getter to invoke.
      *args: Arguments, compatible with those of tf.get_variable.
      **kwargs: Keyword arguments, compatible with those of tf.get_variable.

    Returns:
      The result of invoking `getter(*args, **kwargs)` except that certain
      kwargs entries may have been overridden.
    """
    kwargs.update(override_kwargs)
    return getter(*args, **kwargs)

  return custom_getter