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


Python util.mergeFunctionMetadata方法代码示例

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


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

示例1: test_mergedFunctionBehavesLikeMergeTarget

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def test_mergedFunctionBehavesLikeMergeTarget(self):
        """
        After merging C{foo}'s data into C{bar}, the returned function behaves
        as if it is C{bar}.
        """
        foo_object = object()
        bar_object = object()

        def foo():
            return foo_object

        def bar(x, y, ab, c=10, *d, **e):
            (a, b) = ab
            return bar_object

        baz = util.mergeFunctionMetadata(foo, bar)
        self.assertIs(baz(1, 2, (3, 4), quux=10), bar_object) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_util.py

示例2: test_docstringIsMerged

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def test_docstringIsMerged(self):
        """
        Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
        """

        def foo():
            """
            This is foo.
            """

        def bar():
            """
            This is bar.
            """

        baz = util.mergeFunctionMetadata(foo, bar)
        self.assertEqual(baz.__doc__, foo.__doc__) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_util.py

示例3: test_instanceDictionaryIsMerged

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def test_instanceDictionaryIsMerged(self):
        """
        Merging C{foo} into C{bar} returns a function with C{bar}'s
        dictionary, updated by C{foo}'s.
        """

        def foo():
            pass
        foo.a = 1
        foo.b = 2

        def bar():
            pass
        bar.b = 3
        bar.c = 4

        baz = util.mergeFunctionMetadata(foo, bar)
        self.assertEqual(foo.a, baz.a)
        self.assertEqual(foo.b, baz.b)
        self.assertEqual(bar.c, baz.c) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_util.py

示例4: goodDecorator

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def goodDecorator(fn):
    """
    Decorate a function and preserve the original name.
    """
    def nameCollision(*args, **kwargs):
        return fn(*args, **kwargs)
    return mergeFunctionMetadata(fn, nameCollision) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:sample.py

示例5: test_moduleIsMerged

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def test_moduleIsMerged(self):
        """
        Merging C{foo} into C{bar} returns a function with C{foo}'s
        C{__module__}.
        """
        def foo():
            pass

        def bar():
            pass
        bar.__module__ = 'somewhere.else'

        baz = util.mergeFunctionMetadata(foo, bar)
        self.assertEqual(baz.__module__, foo.__module__) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_util.py

示例6: test_nameIsMerged

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def test_nameIsMerged(self):
        """
        Merging C{foo} into C{bar} returns a function with C{foo}'s name.
        """

        def foo():
            pass

        def bar():
            pass

        baz = util.mergeFunctionMetadata(foo, bar)
        self.assertEqual(baz.__name__, foo.__name__) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_util.py

示例7: atSpecifiedTime

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def atSpecifiedTime(when, func):
    def inner(*a, **kw):
        orig = time.time
        time.time = lambda: when
        try:
            return func(*a, **kw)
        finally:
            time.time = orig
    return util.mergeFunctionMetadata(func, inner) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:11,代码来源:test_http_headers.py

示例8: not_reentrant

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def not_reentrant(function, _calls={}):
    """Decorates a function as not being re-entrant.

    The decorated function will raise an error if called from within itself.
    """
    def decorated(*args, **kwargs):
        if _calls.get(function, False):
            raise ReentryError(function)
        _calls[function] = True
        try:
            return function(*args, **kwargs)
        finally:
            _calls[function] = False
    return mergeFunctionMetadata(function, decorated) 
开发者ID:byt3bl33d3r,项目名称:pth-toolkit,代码行数:16,代码来源:_spinner.py

示例9: suppressWarnings

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def suppressWarnings(f, *suppressedWarnings):
    """
    Wrap C{f} in a callable which suppresses the indicated warnings before
    invoking C{f} and unsuppresses them afterwards.  If f returns a Deferred,
    warnings will remain suppressed until the Deferred fires.
    """
    def warningSuppressingWrapper(*a, **kw):
        return runWithWarningsSuppressed(suppressedWarnings, f, *a, **kw)
    return tputil.mergeFunctionMetadata(f, warningSuppressingWrapper) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:11,代码来源:utils.py

示例10: deprecated

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def deprecated(version):
    """
    Return a decorator that marks callables as deprecated.

    @type version: L{twisted.python.versions.Version}
    @param version: The version in which the callable will be marked as
        having been deprecated.  The decorated function will be annotated
        with this version, having it set as its C{deprecatedVersion}
        attribute.
    """
    def deprecationDecorator(function):
        """
        Decorator that marks C{function} as deprecated.
        """
        warningString = getDeprecationWarningString(function, version)

        def deprecatedFunction(*args, **kwargs):
            warn(
                warningString,
                DeprecationWarning,
                stacklevel=2)
            return function(*args, **kwargs)

        deprecatedFunction = mergeFunctionMetadata(
            function, deprecatedFunction)
        _appendToDocstring(deprecatedFunction,
                           _getDeprecationDocstring(version))
        deprecatedFunction.deprecatedVersion = version
        return deprecatedFunction

    return deprecationDecorator 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:33,代码来源:deprecate.py

示例11: _fireWhenDoneFunc

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def _fireWhenDoneFunc(self, d, f):
        """Returns closure that when called calls f and then callbacks d.
        """
        from twisted.python import util as tputil
        def newf(*args, **kw):
            rtn = f(*args, **kw)
            d.callback('')
            return rtn
        return tputil.mergeFunctionMetadata(f, newf) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:11,代码来源:test_tcp.py

示例12: _withCacheness

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def _withCacheness(meth):
        """
        This is a paranoid test wrapper, that calls C{meth} 2 times, clear the
        cache, and calls it 2 other times. It's supposed to ensure that the
        plugin system behaves correctly no matter what the state of the cache
        is.
        """
        def wrapped(self):
            meth(self)
            meth(self)
            self._clearCache()
            meth(self)
            meth(self)
        return mergeFunctionMetadata(meth, wrapped) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:16,代码来源:test_plugin.py

示例13: deferredGenerator

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def deferredGenerator(f):
    """
    See L{waitForDeferred}.
    """
    def unwindGenerator(*args, **kwargs):
        return _deferGenerator(f(*args, **kwargs))
    return mergeFunctionMetadata(f, unwindGenerator) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:defer.py

示例14: transacted

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def transacted(func):
    """
    Return a callable which will invoke C{func} in a transaction using the
    C{store} attribute of the first parameter passed to it.  Typically this is
    used to create Item methods which are automatically run in a transaction.

    The attributes of the returned callable will resemble those of C{func} as
    closely as L{twisted.python.util.mergeFunctionMetadata} can make them.
    """
    def transactionified(item, *a, **kw):
        return item.store.transact(func, item, *a, **kw)
    return mergeFunctionMetadata(func, transactionified) 
开发者ID:twisted,项目名称:axiom,代码行数:14,代码来源:item.py

示例15: inlineCallbacks

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import mergeFunctionMetadata [as 别名]
def inlineCallbacks(f):
    """
    WARNING: this function will not work in Python 2.4 and earlier!

    inlineCallbacks helps you write Deferred-using code that looks like a
    regular sequential function. This function uses features of Python 2.5
    generators.  If you need to be compatible with Python 2.4 or before, use
    the L{deferredGenerator} function instead, which accomplishes the same
    thing, but with somewhat more boilerplate.  For example::

        @inlineCallBacks
        def thingummy():
            thing = yield makeSomeRequestResultingInDeferred()
            print thing #the result! hoorj!

    When you call anything that results in a L{Deferred}, you can simply yield it;
    your generator will automatically be resumed when the Deferred's result is
    available. The generator will be sent the result of the L{Deferred} with the
    'send' method on generators, or if the result was a failure, 'throw'.

    Your inlineCallbacks-enabled generator will return a L{Deferred} object, which
    will result in the return value of the generator (or will fail with a
    failure object if your generator raises an unhandled exception). Note that
    you can't use C{return result} to return a value; use C{returnValue(result)}
    instead. Falling off the end of the generator, or simply using C{return}
    will cause the L{Deferred} to have a result of C{None}.

    The L{Deferred} returned from your deferred generator may errback if your
    generator raised an exception::

        @inlineCallbacks
        def thingummy():
            thing = yield makeSomeRequestResultingInDeferred()
            if thing == 'I love Twisted':
                # will become the result of the Deferred
                returnValue('TWISTED IS GREAT!')
            else:
                # will trigger an errback
                raise Exception('DESTROY ALL LIFE')
    """
    def unwindGenerator(*args, **kwargs):
        return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
    return mergeFunctionMetadata(f, unwindGenerator)


## DeferredLock/DeferredQueue 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:48,代码来源:defer.py


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