How to use the decorator.decorate 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 smarie / python-pytest-steps / pytest_steps / steps_py3_api.py View on Github external
# Then create the final function that will be executed when the user calls
        def _execute_self_and_inner(f_with_new_api, *args, **kwargs):
            # First execute the function with the new api
            # Typically that function will be empty but this ensures that python does the args checking:
            # error messages will be the 'python 3' ones in case of mistake.
            #
            # In addition the new api functions can do further checks (not recommended, for consistency with inner func)
            # note that they should not produce results - they will be discarded if so.
            f_with_new_api(*args, **kwargs)

            # then execute the inner function
            return f_with_old_api(*args, **kwargs)

        # Use decorate to preserve everything (name, signature...)
        return decorate(f_with_new_api, _execute_self_and_inner)
github dmlc / dgl / python / dgl / _ffi / base.py View on Github external
def decorate(func, fwrapped):
    """A wrapper call of decorator package, differs to call time

    Parameters
    ----------
    func : function
        The original function

    fwrapped : function
        The wrapped function
    """
    import decorator
    return decorator.decorate(func, fwrapped)
github bachng2017 / RENAT / VChannel.py View on Github external
def with_reconnect(f):
    return decorate(f, _with_reconnect)
github wxWidgets / wxPython-Classic / wxPython / wx / py / wxd / d_stc.py View on Github external
When you import stc from this module, all of the classes get decorated
with docstrings from our decoration class definitions.
"""

__author__ = "Patrick K. O'Brien "
__cvsid__ = "$Id$"
__revision__ = "$Revision$"[11:-2]

from wxPython import stc

import stc_

import decorator

decorator.decorate(real=stc, decoration=stc_)
github navytux / pygolang / golang / __init__.py View on Github external
def _func(f):
    # @staticmethod & friends require special care:
    # unpack f first to original func and then repack back after wrapping.
    fclass = None
    if isinstance(f, (staticmethod, classmethod)):
        fclass = type(f)
        f = f.__func__

    def _(f, *argv, **kw):
        # run f under separate frame, where defer will register calls.
        __goframe__ = _GoFrame()
        with __goframe__:
            return f(*argv, **kw)

    # keep all f attributes, like __name__, __doc__, etc on _
    _ = decorator.decorate(f, _)

    # repack _ into e.g. @staticmethod if that was used on f.
    if fclass is not None:
        _ = fclass(_)

    return _
github DocMarty84 / koozic / odoo / api.py View on Github external
def model_create_single(method):
    """ Decorate a method that takes a dictionary and creates a single record.
        The method may be called with either a single dict or a list of dicts::

            record = model.create(vals)
            records = model.create([vals, ...])
    """
    wrapper = decorate(method, _model_create_single)
    wrapper._api = 'model_create'
    return wrapper
github invinst / ResponseBot / responsebot / responsebot_client.py View on Github external
raise APIQuotaError(str(e))
        except TweepError as e:
            if e.api_code == TWITTER_AUTOMATED_REQUEST_ERROR:
                raise AutomatedRequestError
            elif e.api_code == TWITTER_OVER_CAPACITY_ERROR:
                raise OverCapacityError
            elif e.api_code in [TWITTER_CHARACTER_LIMIT_ERROR_1, TWITTER_CHARACTER_LIMIT_ERROR_2]:
                raise CharacterLimitError
            elif e.api_code == TWITTER_DAILY_STATUS_UPDATE_LIMIT_ERROR:
                raise DailyStatusUpdateError
            elif e.api_code == TWITTER_STATUS_DUPLICATE_ERROR:
                raise StatusDuplicateError
            else:
                raise

    return decorate(func, func_wrapper)
github halcy / Mastodon.py / mastodon / Mastodon.py View on Github external
if not self.version_check_mode == "none":
                if self.version_check_mode == "created":
                    version = created_ver
                else:
                    version = bigger_version(last_changed_ver, return_value_ver)
                major, minor, patch = parse_version_string(version)
                if major > self.mastodon_major:
                    raise MastodonVersionError("Version check failed (Need version " + version + ")")
                elif major == self.mastodon_major and minor > self.mastodon_minor:
                    print(self.mastodon_minor)
                    raise MastodonVersionError("Version check failed (Need version " + version + ")")
                elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch:
                    raise MastodonVersionError("Version check failed (Need version " + version + ", patch is " + str(self.mastodon_patch) + ")")
            return function(self, *args, **kwargs)
        function.__doc__ = function.__doc__ + "\n\n        *Added: Mastodon v" + created_ver + ", last changed: Mastodon v" + last_changed_ver + "*"
        return decorate(function, wrapper)
    return api_min_version_decorator
github janushendersonassetallocation / loman / loman / computeengine.py View on Github external
def inner(f):
        if name is None:
            comp.add_node(f.__name__, f, *args, **kw)
        else:
            comp.add_node(name, f, *args, **kw)
        return decorator.decorate(f, _node)
    return inner