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


Python defer.FAILURE属性代码示例

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


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

示例1: _runSequentially

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _runSequentially(callables, stopOnFirstError=False):
    """
    Run the given callables one after the other. If a callable returns a
    Deferred, wait until it has finished before running the next callable.

    @param callables: An iterable of callables that take no parameters.

    @param stopOnFirstError: If True, then stop running callables as soon as
        one raises an exception or fires an errback. False by default.

    @return: A L{Deferred} that fires a list of C{(flag, value)} tuples. Each
        tuple will be either C{(SUCCESS, <return value>)} or C{(FAILURE,
        <Failure>)}.
    """
    results = []
    for f in callables:
        d = defer.maybeDeferred(f)
        try:
            thing = yield d
            results.append((defer.SUCCESS, thing))
        except Exception:
            results.append((defer.FAILURE, Failure()))
            if stopOnFirstError:
                break
    defer.returnValue(results) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:util.py

示例2: _assertFailures

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _assertFailures(self, failures, *expectedFailures):
        for flag, failure in failures:
            self.assertEqual(flag, defer.FAILURE)
            failure.trap(*expectedFailures)
        return None 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_cred.py

示例3: _cbDeferRunCleanups

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _cbDeferRunCleanups(self, cleanupResults, result):
        for flag, testFailure in cleanupResults:
            if flag == defer.FAILURE:
                result.addError(self, testFailure)
                if testFailure.check(KeyboardInterrupt):
                    result.stop()
                self._passed = False 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:_asynctest.py

示例4: test_singleSynchronousFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_singleSynchronousFailure(self):
        """
        When given a callable that raises an exception, include a Failure for
        that exception in the results list, tagged with a FAILURE flag.
        """
        d = util._runSequentially([lambda: self.fail('foo')])
        def check(results):
            [(flag, fail)] = results
            fail.trap(self.failureException)
            self.assertEqual(fail.getErrorMessage(), 'foo')
            self.assertEqual(flag, defer.FAILURE)
        self.assertDeferredResult(d, check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_util.py

示例5: test_singleAsynchronousFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_singleAsynchronousFailure(self):
        """
        When given a callable that returns a failing Deferred, include the
        failure the results list, tagged with a FAILURE flag.
        """
        d = util._runSequentially([lambda: defer.fail(ValueError('foo'))])
        def check(results):
            [(flag, fail)] = results
            fail.trap(ValueError)
            self.assertEqual(fail.getErrorMessage(), 'foo')
            self.assertEqual(flag, defer.FAILURE)
        self.assertDeferredResult(d, check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_util.py

示例6: test_stopOnFirstError

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_stopOnFirstError(self):
        """
        If the C{stopOnFirstError} option is passed to C{runSequentially}, then
        no further callables are called after the first exception is raised.
        """
        d = util._runSequentially([lambda: self.fail('foo'), lambda: 'bar'],
                                  stopOnFirstError=True)
        def check(results):
            [(flag1, fail)] = results
            fail.trap(self.failureException)
            self.assertEqual(flag1, defer.FAILURE)
            self.assertEqual(fail.getErrorMessage(), 'foo')
        self.assertDeferredResult(d, check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_util.py

示例7: testDeferredList

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def testDeferredList(self):
        defr1 = defer.Deferred()
        defr2 = defer.Deferred()
        defr3 = defer.Deferred()
        dl = defer.DeferredList([defr1, defr2, defr3])
        result = []
        def cb(resultList, result=result):
            result.extend(resultList)
        def catch(err):
            return None
        dl.addCallbacks(cb, cb)
        defr1.callback("1")
        defr2.addErrback(catch)
        # "catch" is added to eat the GenericError that will be passed on by
        # the DeferredList's callback on defr2. If left unhandled, the
        # Failure object would cause a log.err() warning about "Unhandled
        # error in Deferred". Twisted's pyunit watches for log.err calls and
        # treats them as failures. So "catch" must eat the error to prevent
        # it from flunking the test.
        defr2.errback(GenericError("2"))
        defr3.callback("3")
        self.assertEqual([result[0],
                    #result[1][1] is now a Failure instead of an Exception
                              (result[1][0], str(result[1][1].value)),
                              result[2]],

                             [(defer.SUCCESS, "1"),
                              (defer.FAILURE, "2"),
                              (defer.SUCCESS, "3")]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:test_defer.py

示例8: _assertFailures

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _assertFailures(self, failures, *expectedFailures):
        for flag, failure in failures:
            self.failUnlessEqual(flag, defer.FAILURE)
            failure.trap(*expectedFailures) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:6,代码来源:test_fileupload.py

示例9: _runSequentially

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _runSequentially(callables, stopOnFirstError=False):
    """
    Run the given callables one after the other. If a callable returns a
    Deferred, wait until it has finished before running the next callable.

    @param callables: An iterable of callables that take no parameters.

    @param stopOnFirstError: If True, then stop running callables as soon as
        one raises an exception or fires an errback. False by default.

    @return: A L{Deferred} that fires a list of C{(flag, value)} tuples. Each
        tuple will be either C{(SUCCESS, <return value>)} or C{(FAILURE,
        <Failure>)}.
    """
    results = []
    for f in callables:
        d = defer.maybeDeferred(f)
        thing = defer.waitForDeferred(d)
        yield thing
        try:
            results.append((defer.SUCCESS, thing.getResult()))
        except:
            results.append((defer.FAILURE, Failure()))
            if stopOnFirstError:
                break
    yield results 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:28,代码来源:util.py

示例10: test_singleSynchronousFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_singleSynchronousFailure(self):
        """
        When given a callable that raises an exception, include a Failure for
        that exception in the results list, tagged with a FAILURE flag.
        """
        d = util._runSequentially([lambda: self.fail('foo')])
        def check(results):
            [(flag, fail)] = results
            fail.trap(self.failureException)
            self.assertEqual(fail.getErrorMessage(), 'foo')
            self.assertEqual(flag, defer.FAILURE)
        return d.addCallback(check) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:14,代码来源:test_util.py

示例11: test_singleAsynchronousFailure

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_singleAsynchronousFailure(self):
        """
        When given a callable that returns a failing Deferred, include the
        failure the results list, tagged with a FAILURE flag.
        """
        d = util._runSequentially([lambda: defer.fail(ValueError('foo'))])
        def check(results):
            [(flag, fail)] = results
            fail.trap(ValueError)
            self.assertEqual(fail.getErrorMessage(), 'foo')
            self.assertEqual(flag, defer.FAILURE)
        return d.addCallback(check) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:14,代码来源:test_util.py

示例12: test_continuesAfterError

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_continuesAfterError(self):
        """
        If one of the callables raises an error, then runSequentially continues
        to run the remaining callables.
        """
        d = util._runSequentially([lambda: self.fail('foo'), lambda: 'bar'])
        def check(results):
            [(flag1, fail), (flag2, result)] = results
            fail.trap(self.failureException)
            self.assertEqual(flag1, defer.FAILURE)
            self.assertEqual(fail.getErrorMessage(), 'foo')
            self.assertEqual(flag2, defer.SUCCESS)
            self.assertEqual(result, 'bar')
        return d.addCallback(check) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:16,代码来源:test_util.py

示例13: test_stopOnFirstError

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def test_stopOnFirstError(self):
        """
        If the C{stopOnFirstError} option is passed to C{runSequentially}, then
        no further callables are called after the first exception is raised.
        """
        d = util._runSequentially([lambda: self.fail('foo'), lambda: 'bar'],
                                  stopOnFirstError=True)
        def check(results):
            [(flag1, fail)] = results
            fail.trap(self.failureException)
            self.assertEqual(flag1, defer.FAILURE)
            self.assertEqual(fail.getErrorMessage(), 'foo')
        return d.addCallback(check) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:15,代码来源:test_util.py

示例14: _cbDeferRunCleanups

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def _cbDeferRunCleanups(self, cleanupResults, result):
        for flag, failure in cleanupResults:
            if flag == defer.FAILURE:
                result.addError(self, failure)
                if failure.check(KeyboardInterrupt):
                    result.stop()
                self._passed = False 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:9,代码来源:unittest.py

示例15: testDeferredList

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import FAILURE [as 别名]
def testDeferredList(self):
        defr1 = defer.Deferred()
        defr2 = defer.Deferred()
        defr3 = defer.Deferred()
        dl = defer.DeferredList([defr1, defr2, defr3])
        result = []
        def cb(resultList, result=result):
            result.extend(resultList)
        def catch(err):
            return None
        dl.addCallbacks(cb, cb)
        defr1.callback("1")
        defr2.addErrback(catch)
        # "catch" is added to eat the GenericError that will be passed on by
        # the DeferredList's callback on defr2. If left unhandled, the
        # Failure object would cause a log.err() warning about "Unhandled
        # error in Deferred". Twisted's pyunit watches for log.err calls and
        # treats them as failures. So "catch" must eat the error to prevent
        # it from flunking the test.
        defr2.errback(GenericError("2"))
        defr3.callback("3")
        self.failUnlessEqual([result[0],
                    #result[1][1] is now a Failure instead of an Exception
                              (result[1][0], str(result[1][1].value)),
                              result[2]],

                             [(defer.SUCCESS, "1"),
                              (defer.FAILURE, "2"),
                              (defer.SUCCESS, "3")]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:31,代码来源:test_defer.py


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