How to use the decorator.decorator 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 Mizzou-CBMI / COSMOS2 / cosmos / core / cmd_fxn / signature.py View on Github external
def real_decorator(fxn, *args, **kwargs):
        if getattr(fxn, "skip_wrap", False):
            r = fxn(*args, **kwargs)
            return r
        else:
            r = fxn(*args, **kwargs)
            assert isinstance(r, str) or r is None, (
                "cmd_fxn %s did not return a str or None" % fxn
            )
            if r is None:
                return None
            else:
                return default_prepend(task) + extra_prepend + r + extra_append

    return decorator.decorator(real_decorator)
github michael-lazar / rtv / rtv / packages / praw / decorators.py View on Github external
@decorator.decorator
def require_captcha(function, *args, **kwargs):
    """Return a decorator for methods that require captchas."""
    raise_captcha_exception = kwargs.pop('raise_captcha_exception', False)
    captcha_id = None

    # Get a handle to the reddit session
    if hasattr(args[0], 'reddit_session'):
        reddit_session = args[0].reddit_session
    else:
        reddit_session = args[0]

    while True:
        try:
            if captcha_id:
                captcha_answer = _get_captcha(reddit_session, captcha_id)
github fp7-ofelia / ocf / expedient / src / python / plugins / openflow / plugin / gapi / rpc.py View on Github external
credentials = args[1]
        else:
            slice_urn = None
            credentials = args[0]
            
        cred_verifier = CredentialVerifier(settings.GCF_X509_TRUSTED_CERT_DIR)
            
        cred_verifier.verify_from_strings(
            client_cert, credentials,
            slice_urn, PRIVS_MAP[func.func_name])

        logger.debug("Creds pass")
        
        return func(*args, **kw)
        
    return decorator(require_creds)
github scherroman / mugen / mugen / utility.py View on Github external
def preprocess_args(fun: Callable, varnames: List[str]):
    """ 
    Applies fun to variables in varnames before launching the function 
    """
    def wrapper(f, *a, **kw):
        func_code = f.__code__

        names = func_code.co_varnames
        new_a = [fun(arg) if (name in varnames) else arg
                 for (arg, name) in zip(a, names)]
        new_kw = {k: fun(v) if k in varnames else v
                  for (k, v) in kw.items()}
        return f(*new_a, **new_kw)

    return decorator.decorator(wrapper)
github dsacre / mididings / mididings / misc.py View on Github external
def __call__(self, f):
        f._deprecated = True
        return decorator.decorator(self.wrapper, f)
github microsoft / NimbusML / src / python / nimbusml / internal / utils / utils.py View on Github external
    @decorator.decorator
    def trace(func, *args, **kwargs):
        """
        Decorator for tracing enter and exit times
        """

        verbose = 0
        if 'verbose' in kwargs:
            verbose = kwargs['verbose']
        if not isinstance(verbose, six.integer_types):
            raise TypeError(
                "Misaligned parameters. verbose must be int "
                "not '{0}': {1}".format(
                    type(verbose), verbose))
        if verbose > 0:
            logger_trace.info(
                "[%s] enter %s.%s " %
github edublancas / sklearn-evaluation / sklearn_evaluation / validate.py View on Github external
    @decorator
    def argument_is_proportion(func, *args, **kwargs):
        """Validate that an agument is a proportion [0, 1.0]
        """

        try:
            value = kwargs[argname]
        except Exception:
            try:
                fn_args = inspect.getargspec(func).args
                idx = fn_args.index(argname)
                value = args[idx]
            except Exception:
                value = None
        # Validate value, but only if has a value
        if (not (0 <= value <= 1.0)) and value is not None:
            raise ValueError('{argname} must be between 0 and 1.0'
github Newterm / szarp / wx / sync / ssconfd / ssconf.py View on Github external
	@decorator
	def checkuser(f, *args, **kw):
		"""
		Checks for user credentials, set self.user_dict to user data.
		"""
		args[0].read_db()
		u = escape_xpath(args[1])
		p = args[2]
		search = args[0].db.find(".//{%s}user[@name='%s']" % (ss_namespace, u))
		if search is None:
			raise AuthException("invalid user or password")
		if p != search.attrib['password']:
			raise AuthException("invalid user or password")
		args[0].user_dict = dict()
		for k in ('name', 'email', 'expired', 'hwkey', 'server'):
			args[0].user_dict[k] = search.attrib[k]
		bases = args[0].get_available_bases(args[0].admin, args[0].passhash)
github ipython / ipyparallel / ipyparallel / client / view.py View on Github external
@decorator
def save_ids(f, self, *args, **kwargs):
    """Keep our history and outstanding attributes up to date after a method call."""
    n_previous = len(self.client.history)
    try:
        ret = f(self, *args, **kwargs)
    finally:
        nmsgs = len(self.client.history) - n_previous
        msg_ids = self.client.history[-nmsgs:]
        self.history.extend(msg_ids)
        self.outstanding.update(msg_ids)
    return ret
github qiime2 / qiime2 / qiime / core / callable.py View on Github external
def _rewrite_wrapper_signature(self, wrapper):
        # Convert the callable's signature into the wrapper's signature and set
        # it on the wrapper.
        return decorator.decorator(
            wrapper, self._callable_sig_converter_(self._callable))