當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。