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


Python defer.deferredGenerator方法代码示例

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


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

示例1: test_deferredGeneratorDeprecated

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def test_deferredGeneratorDeprecated(self):
        """
        L{deferredGenerator} is deprecated.
        """
        @deferredGenerator
        def decoratedFunction():
            yield None

        warnings = self.flushWarnings([self.test_deferredGeneratorDeprecated])
        self.assertEqual(len(warnings), 1)
        self.assertEqual(warnings[0]['category'], DeprecationWarning)
        self.assertEqual(
            warnings[0]['message'],
            "twisted.internet.defer.deferredGenerator was deprecated in "
            "Twisted 15.0.0; please use "
            "twisted.internet.defer.inlineCallbacks instead") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_defgen.py

示例2: testDeferredYielding

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testDeferredYielding(self):
        """
        Ensure that yielding a Deferred directly is trapped as an
        error.
        """
        # See the comment _deferGenerator about d.callback(Deferred).
        def _genDeferred():
            yield getThing()
        _genDeferred = deferredGenerator(_genDeferred)

        return self.assertFailure(_genDeferred(), TypeError)



## This has to be in a string so the new yield syntax doesn't cause a
## syntax error in Python 2.4 and before. 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_defgen.py

示例3: testHandledTerminalFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testHandledTerminalFailure(self):
        """
        Create a Deferred Generator which yields a Deferred which fails and
        handles the exception which results.  Assert that the Deferred
        Generator does not errback its Deferred.
        """
        class TerminalException(Exception):
            pass

        def _genFailure():
            x = waitForDeferred(defer.fail(TerminalException("Handled Terminal Failure")))
            yield x
            try:
                x.getResult()
            except TerminalException:
                pass
        _genFailure = deferredGenerator(_genFailure)
        return _genFailure().addCallback(self.assertEqual, None) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:20,代码来源:test_defgen.py

示例4: testHandledTerminalAsyncFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testHandledTerminalAsyncFailure(self):
        """
        Just like testHandledTerminalFailure, only with a Deferred which fires
        asynchronously with an error.
        """
        class TerminalException(Exception):
            pass


        d = defer.Deferred()
        def _genFailure():
            x = waitForDeferred(d)
            yield x
            try:
                x.getResult()
            except TerminalException:
                pass
        _genFailure = deferredGenerator(_genFailure)
        deferredGeneratorResultDeferred = _genFailure()
        d.errback(TerminalException("Handled Terminal Failure"))
        return deferredGeneratorResultDeferred.addCallback(
            self.assertEqual, None) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:24,代码来源:test_defgen.py

示例5: testBasics

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testBasics(self):
        """
        Test that a normal deferredGenerator works.  Tests yielding a
        deferred which callbacks, as well as a deferred errbacks. Also
        ensures returning a final value works.
        """

        return self._genBasics().addCallback(self.assertEqual, 'WOOSH') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_defgen.py

示例6: deprecatedDeferredGenerator

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def deprecatedDeferredGenerator(f):
    """
    Calls L{deferredGenerator} while suppressing the deprecation warning.

    @param f: Function to call
    @return: Return value of function.
    """
    return runWithWarningsSuppressed(
        [ SUPPRESS(message="twisted.internet.defer.deferredGenerator was "
                          "deprecated") ],
        deferredGenerator, f) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_defgen.py

示例7: testBuggyGen

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testBuggyGen(self):
        def _genError():
            yield waitForDeferred(getThing())
            1/0
        _genError = deferredGenerator(_genError)

        return self.assertFailure(_genError(), ZeroDivisionError) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:test_defgen.py

示例8: testNothing

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testNothing(self):
        def _genNothing():
            if 0: yield 1
        _genNothing = deferredGenerator(_genNothing)

        return _genNothing().addCallback(self.assertEqual, None) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:8,代码来源:test_defgen.py

示例9: testDeferredYielding

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testDeferredYielding(self):
        # See the comment _deferGenerator about d.callback(Deferred).
        def _genDeferred():
            yield getThing()
        _genDeferred = deferredGenerator(_genDeferred)

        return self.assertFailure(_genDeferred(), TypeError) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:test_defgen.py

示例10: testStackUsage2

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def testStackUsage2(self):
        def _loop():
            for x in range(5000):
                # Test with yielding a random value
                yield 1
            yield 0

        _loop = deferredGenerator(_loop)
        return _loop().addCallback(self.assertEqual, 0) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:11,代码来源:test_defgen.py

示例11: quotaSize

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import deferredGenerator [as 别名]
def quotaSize(self, request):
        """
        Get the size of this resource.
        TODO: Take into account size of dead-properties. Does stat
            include xattrs size?

        @return: an L{Deferred} with a C{int} result containing the size of the resource.
        """
        if self.isCollection():
            def walktree(top):
                """
                Recursively descend the directory tree rooted at top,
                calling the callback function for each regular file

                @param top: L{FilePath} for the directory to walk.
                """

                total = 0
                for f in top.listdir():
                    child = top.child(f)
                    if child.isdir():
                        # It's a directory, recurse into it
                        result = waitForDeferred(walktree(child))
                        yield result
                        total += result.getResult()
                    elif child.isfile():
                        # It's a file, call the callback function
                        total += child.getsize()
                    else:
                        # Unknown file type, print a message
                        pass

                yield total

            walktree = deferredGenerator(walktree)

            return walktree(self.fp)
        else:
            return succeed(self.fp.getsize())

    ##
    # Workarounds for issues with File
    ## 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:45,代码来源:static.py


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