How to use the decorator.getargspec function in decorator

To help you get started, we’ve selected a few decorator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Morgan-Stanley / treadmill / lib / python / treadmill / cli / admin / invoke.py View on Github external
def make_command(parent, name, func):
    """Make a command using reflection on the function."""
    # Disable "Too many branches" warning.
    #
    # pylint: disable=R0912
    argspec = decorator.getargspec(func)
    args = list(argspec.args)
    defaults = argspec.defaults
    if defaults is None:
        defaults = []
    else:
        defaults = list(defaults)

    @parent.command(name=name, help=func.__doc__)
    def command(*args, **kwargs):
        """Constructs a command handler."""
        try:
            if 'rsrc' in kwargs:
                with io.open(kwargs['rsrc'], 'rb') as fd:
                    kwargs['rsrc'] = yaml.load(stream=fd)

            formatter = cli.make_formatter(None)
github Morgan-Stanley / treadmill / lib / python / treadmill / schema.py View on Github external
def decorated(func, *args):
        """Validates arguments given schemas."""
        # decorator.decorator swallows kwargs for some reason.
        argspec = decorator.getargspec(func)
        defaults = []
        if argspec.defaults:
            defaults = argspec.defaults

        kwargs = {}
        for kw_name, kw_value, kw_default in zip(reversed(argspec.args),
                                                 reversed(args),
                                                 defaults):
            if kw_value != kw_default:
                kwargs[kw_name] = kw_value

        if defaults:
            args = list(args)[:-len(defaults)]
        else:
            args = list(args)
        valid_args, valid_kwargs = validate(args, kwargs)