当前位置: 首页>>代码示例>>Python>>正文


Python util.ArgReplacer方法代码示例

本文整理汇总了Python中tornado.util.ArgReplacer方法的典型用法代码示例。如果您正苦于以下问题:Python util.ArgReplacer方法的具体用法?Python util.ArgReplacer怎么用?Python util.ArgReplacer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.util的用法示例。


在下文中一共展示了util.ArgReplacer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _auth_return_future

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def _auth_return_future(f):
    """Similar to tornado.concurrent.return_future, but uses the auth
    module's legacy callback interface.

    Note that when using this decorator the ``callback`` parameter
    inside the function will actually be a future.
    """
    replacer = ArgReplacer(f, 'callback')

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        future = TracebackFuture()
        callback, args, kwargs = replacer.replace(future, args, kwargs)
        if callback is not None:
            future.add_done_callback(
                functools.partial(_auth_future_to_callback, callback))
        f(*args, **kwargs)
        return future
    return wrapper 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:21,代码来源:auth.py

示例2: _auth_return_future

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def _auth_return_future(f):
    """Similar to tornado.concurrent.return_future, but uses the auth
    module's legacy callback interface.

    Note that when using this decorator the ``callback`` parameter
    inside the function will actually be a future.
    """
    replacer = ArgReplacer(f, 'callback')

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        future = TracebackFuture()
        callback, args, kwargs = replacer.replace(future, args, kwargs)
        if callback is not None:
            future.add_done_callback(
                functools.partial(_auth_future_to_callback, callback))

        def handle_exception(typ, value, tb):
            if future.done():
                return False
            else:
                future.set_exc_info((typ, value, tb))
                return True
        with ExceptionStackContext(handle_exception):
            f(*args, **kwargs)
        return future
    return wrapper 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:29,代码来源:auth.py

示例3: setUp

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def setUp(self):
        def function(x, y, callback=None, z=None):
            pass
        self.replacer = ArgReplacer(function, 'callback') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:util_test.py

示例4: test_arg_replacer_function

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def test_arg_replacer_function(self):
        replacer = ArgReplacer(cythonapp.function_with_args, 'two')
        args = (1, 'old', 3)
        kwargs = {}
        self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
        self.assertEqual(replacer.replace('new', args, kwargs),
                         ('old', [1, 'new', 3], {})) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:cythonapp_test.py

示例5: _auth_return_future

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def _auth_return_future(f):
    """Similar to tornado.concurrent.return_future, but uses the auth
    module's legacy callback interface.

    Note that when using this decorator the ``callback`` parameter
    inside the function will actually be a future.

    .. deprecated:: 5.1
       Will be removed in 6.0.
    """
    replacer = ArgReplacer(f, 'callback')

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        future = Future()
        callback, args, kwargs = replacer.replace(future, args, kwargs)
        if callback is not None:
            warnings.warn("callback arguments are deprecated, use the returned Future instead",
                          DeprecationWarning)
            future.add_done_callback(
                wrap(functools.partial(_auth_future_to_callback, callback)))

        def handle_exception(typ, value, tb):
            if future.done():
                return False
            else:
                future_set_exc_info(future, (typ, value, tb))
                return True
        with ExceptionStackContext(handle_exception, delay_warning=True):
            f(*args, **kwargs)
        return future
    return wrapper 
开发者ID:tp4a,项目名称:teleport,代码行数:34,代码来源:auth.py

示例6: _non_deprecated_return_future

# 需要导入模块: from tornado import util [as 别名]
# 或者: from tornado.util import ArgReplacer [as 别名]
def _non_deprecated_return_future(f, warn=False):
    # Allow auth.py to use this decorator without triggering
    # deprecation warnings. This will go away once auth.py has removed
    # its legacy interfaces in 6.0.
    replacer = ArgReplacer(f, 'callback')

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        future = Future()
        callback, args, kwargs = replacer.replace(
            lambda value=_NO_RESULT: future_set_result_unless_cancelled(future, value),
            args, kwargs)

        def handle_error(typ, value, tb):
            future_set_exc_info(future, (typ, value, tb))
            return True
        exc_info = None
        esc = ExceptionStackContext(handle_error, delay_warning=True)
        with esc:
            if not warn:
                # HACK: In non-deprecated mode (only used in auth.py),
                # suppress the warning entirely. Since this is added
                # in a 5.1 patch release and already removed in 6.0
                # I'm prioritizing a minimial change instead of a
                # clean solution.
                esc.delay_warning = False
            try:
                result = f(*args, **kwargs)
                if result is not None:
                    raise ReturnValueIgnoredError(
                        "@return_future should not be used with functions "
                        "that return values")
            except:
                exc_info = sys.exc_info()
                raise
        if exc_info is not None:
            # If the initial synchronous part of f() raised an exception,
            # go ahead and raise it to the caller directly without waiting
            # for them to inspect the Future.
            future.result()

        # If the caller passed in a callback, schedule it to be called
        # when the future resolves.  It is important that this happens
        # just before we return the future, or else we risk confusing
        # stack contexts with multiple exceptions (one here with the
        # immediate exception, and again when the future resolves and
        # the callback triggers its exception by calling future.result()).
        if callback is not None:
            warnings.warn("callback arguments are deprecated, use the returned Future instead",
                          DeprecationWarning)

            def run_callback(future):
                result = future.result()
                if result is _NO_RESULT:
                    callback()
                else:
                    callback(future.result())
            future_add_done_callback(future, wrap(run_callback))
        return future
    return wrapper 
开发者ID:tp4a,项目名称:teleport,代码行数:62,代码来源:concurrent.py


注:本文中的tornado.util.ArgReplacer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。