當前位置: 首頁>>代碼示例>>Python>>正文


Python functools.update_wrapper方法代碼示例

本文整理匯總了Python中functools.update_wrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python functools.update_wrapper方法的具體用法?Python functools.update_wrapper怎麽用?Python functools.update_wrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在functools的用法示例。


在下文中一共展示了functools.update_wrapper方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def __call__(
        self, func, request_definition_builder_factory=RequestDefinitionBuilder
    ):
        spec = utils.get_arg_spec(func)
        arg_handler = arguments.ArgumentAnnotationHandlerBuilder(
            func, spec.args
        )
        builder = request_definition_builder_factory(
            self._method,
            URIDefinitionBuilder(self._uri),
            arg_handler,
            decorators.MethodAnnotationHandlerBuilder(),
        )

        # Need to add the annotations after constructing the request
        # definition builder so it has a chance to attach its listener.
        arg_handler.set_annotations(spec.annotations)

        # Use return value type hint as expected return type
        if spec.return_annotation is not None:
            builder = returns.schema(spec.return_annotation)(builder)
        functools.update_wrapper(builder, func)
        builder = self._add_args(builder)
        return builder 
開發者ID:prkumar,項目名稱:uplink,代碼行數:26,代碼來源:commands.py

示例2: get_urls

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def get_urls(self):
        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        base_viewname = self.get_base_viewname()

        urlpatterns = [
            path('' , include(self.get_subadmin_urls())),
            path('', wrap(self.changelist_view), name='%s_changelist' % base_viewname),
            path('add/', wrap(self.add_view), name='%s_add' % base_viewname),
            re_path(r'^(.+)/history/$', wrap(self.history_view), name='%s_history' % base_viewname),
            re_path(r'^(.+)/delete/$', wrap(self.delete_view), name='%s_delete' % base_viewname),
            re_path(r'^(.+)/change/$', wrap(self.change_view), name='%s_change' % base_viewname),
        ]

        urlpatterns =  urlpatterns
        return urlpatterns 
開發者ID:inueni,項目名稱:django-subadmin,代碼行數:21,代碼來源:__init__.py

示例3: exhaust_stream

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def exhaust_stream(f):
    """Helper decorator for methods that exhausts the stream on return."""

    def wrapper(self, stream, *args, **kwargs):
        try:
            return f(self, stream, *args, **kwargs)
        finally:
            exhaust = getattr(stream, "exhaust", None)
            if exhaust is not None:
                exhaust()
            else:
                while 1:
                    chunk = stream.read(1024 * 64)
                    if not chunk:
                        break

    return update_wrapper(wrapper, f) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:formparser.py

示例4: aiohttp_repeat

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def aiohttp_repeat(func=None, *, count: int = 4):
    if func is None:
        return partial(func, count=count)

    async def wrapper(*args: Any, **kwargs: Any) -> Optional[Any]:
        for pause in range(1, count + 1):
            try:
                return await func(*args, **kwargs)
            except ClientError:
                if pause == count:
                    raise
                logger.debug('aiohttp payload error, repeating...', exc_info=True)
                sleep(pause)
        raise RuntimeError('unreachable')

    wrapper = update_wrapper(wrapper=wrapper, wrapped=func)
    return wrapper 
開發者ID:dephell,項目名稱:dephell,代碼行數:19,代碼來源:networking.py

示例5: _inject_into_cog

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def _inject_into_cog(self, cog):
        # Warning: hacky

        # Make the cog think that get_commands returns this command
        # as well if we inject it without modifying __cog_commands__
        # since that's used for the injection and ejection of cogs.
        def wrapped_get_commands(*, _original=cog.get_commands):
            ret = _original()
            ret.append(self)
            return ret

        # Ditto here
        def wrapped_walk_commands(*, _original=cog.walk_commands):
            yield from _original()
            yield self

        functools.update_wrapper(wrapped_get_commands, cog.get_commands)
        functools.update_wrapper(wrapped_walk_commands, cog.walk_commands)
        cog.get_commands = wrapped_get_commands
        cog.walk_commands = wrapped_walk_commands
        self.cog = cog 
開發者ID:Rapptz,項目名稱:discord.py,代碼行數:23,代碼來源:help.py

示例6: decorator

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def decorator(target):
    """A signature-matching decorator factory."""

    def decorate(fn):
        if not inspect.isfunction(fn):
            raise Exception("not a decoratable function")
        spec = compat.inspect_getfullargspec(fn)
        names = tuple(spec[0]) + spec[1:3] + (fn.__name__,)
        targ_name, fn_name = _unique_symbols(names, 'target', 'fn')

        metadata = dict(target=targ_name, fn=fn_name)
        metadata.update(format_argspec_plus(spec, grouped=False))
        metadata['name'] = fn.__name__
        code = """\
def %(name)s(%(args)s):
    return %(target)s(%(fn)s, %(apply_kw)s)
""" % metadata
        decorated = _exec_code_in_env(code,
                                      {targ_name: target, fn_name: fn},
                                      fn.__name__)
        decorated.__defaults__ = getattr(fn, 'im_func', fn).__defaults__
        decorated.__wrapped__ = fn
        return update_wrapper(decorated, fn)
    return update_wrapper(decorate, target) 
開發者ID:jpush,項目名稱:jbox,代碼行數:26,代碼來源:langhelpers.py

示例7: memoized_instancemethod

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def memoized_instancemethod(fn):
    """Decorate a method memoize its return value.

    Best applied to no-arg methods: memoization is not sensitive to
    argument values, and will always return the same value even when
    called with different arguments.

    """

    def oneshot(self, *args, **kw):
        result = fn(self, *args, **kw)
        memo = lambda *a, **kw: result
        memo.__name__ = fn.__name__
        memo.__doc__ = fn.__doc__
        self.__dict__[fn.__name__] = memo
        return result
    return update_wrapper(oneshot, fn) 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:langhelpers.py

示例8: application

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def application(cls, f):
        """Decorate a function as responder that accepts the request as first
        argument.  This works like the :func:`responder` decorator but the
        function is passed the request object as first argument and the
        request object will be closed automatically::

            @Request.application
            def my_wsgi_app(request):
                return Response('Hello World!')

        :param f: the WSGI callable to decorate
        :return: a new WSGI callable
        """
        #: return a callable that wraps the -2nd argument with the request
        #: and calls the function with all the arguments up to that one and
        #: the request.  The return value is then called with the latest
        #: two arguments.  This makes it possible to use this decorator for
        #: both methods and standalone WSGI functions.
        def application(*args):
            request = cls(args[-2])
            with request:
                return f(*args[:-2] + (request,))(*args[-2:])
        return update_wrapper(application, f) 
開發者ID:jpush,項目名稱:jbox,代碼行數:25,代碼來源:wrappers.py

示例9: exhaust_stream

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def exhaust_stream(f):
    """Helper decorator for methods that exhausts the stream on return."""

    def wrapper(self, stream, *args, **kwargs):
        try:
            return f(self, stream, *args, **kwargs)
        finally:
            exhaust = getattr(stream, 'exhaust', None)
            if exhaust is not None:
                exhaust()
            else:
                while 1:
                    chunk = stream.read(1024 * 64)
                    if not chunk:
                        break
    return update_wrapper(wrapper, f) 
開發者ID:jpush,項目名稱:jbox,代碼行數:18,代碼來源:formparser.py

示例10: update_wrapper

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def update_wrapper(wrapper,
                   wrapped,
                   assigned = functools.WRAPPER_ASSIGNMENTS,
                   updated = functools.WRAPPER_UPDATES):
    """
    Patch two bugs in functools.update_wrapper.
    """
    # workaround for http://bugs.python.org/issue3445
    assigned = tuple(attr for attr in assigned if hasattr(wrapped, attr))
    wrapper = functools.update_wrapper(wrapper, wrapped, assigned, updated)
    # workaround for https://bugs.python.org/issue17482
    wrapper.__wrapped__ = wrapped
    return wrapper 
開發者ID:kislyuk,項目名稱:aegea,代碼行數:15,代碼來源:functools_lru_cache.py

示例11: __init__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def __init__(self, func, class_name=''):
        """Decorate `func`."""
        self.func = func
        functools.update_wrapper(self, func)
        self._caught_signal = None 
開發者ID:TKkk-iOSer,項目名稱:wechat-alfred-workflow,代碼行數:7,代碼來源:util.py

示例12: pass_verbosity

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def pass_verbosity(f):
    """
    Marks a callback as wanting to receive the verbosity as a keyword argument.
    """

    def new_func(*args, **kwargs):
        kwargs["verbosity"] = click.get_current_context().verbosity
        return f(*args, **kwargs)

    return update_wrapper(new_func, f) 
開發者ID:GaretJax,項目名稱:django-click,代碼行數:12,代碼來源:adapter.py

示例13: record_once

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def record_once(self, func: DeferredSetupFunction) -> None:
        """Used to register a deferred action that happens only once."""

        def wrapper(state: "BlueprintSetupState") -> None:
            if state.first_registration:
                func(state)

        self.record(update_wrapper(wrapper, func)) 
開發者ID:pgjones,項目名稱:quart,代碼行數:10,代碼來源:blueprints.py

示例14: with_appcontext

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def with_appcontext(fn: Optional[Callable] = None) -> Callable:
    # decorator was used with parenthesis
    if fn is None:
        return with_appcontext

    @click.pass_context
    def decorator(__ctx: click.Context, *args: Any, **kwargs: Any) -> Any:
        async def _inner() -> Any:
            async with __ctx.ensure_object(ScriptInfo).load_app().app_context():
                return __ctx.invoke(fn, *args, **kwargs)

        return asyncio.run(_inner())

    return functools.update_wrapper(decorator, fn) 
開發者ID:pgjones,項目名稱:quart,代碼行數:16,代碼來源:cli.py

示例15: __init__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import update_wrapper [as 別名]
def __init__(self, bound_func, srcfile, srcline):
        self.srcfile = srcfile
        self.srcline = srcline
        self.bound_func = bound_func
        functools.update_wrapper(self, bound_func)
        self.calls = 0
        # register the block
        myhdl._simulator._blocks.append(self)

        self.name_prefix = None
        self.name = None 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:13,代碼來源:_block.py


注:本文中的functools.update_wrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。