当前位置: 首页>>代码示例>>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;未经允许,请勿转载。