Python twisted.internet.defer.AlreadyCalledError() Examples
The following are 30
code examples of twisted.internet.defer.AlreadyCalledError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.defer
, or try the search function
.
Example #1
Source File: test_defer.py From python-for-android with Apache License 2.0 | 6 votes |
def test_cancelQueueAfterGet(self): """ When canceling a L{Deferred} from a L{DeferredQueue} that does not have a result (i.e., the L{Deferred} has not fired), the cancel causes a L{defer.CancelledError} failure. If the queue has a result later on, it doesn't try to fire the deferred. """ queue = defer.DeferredQueue() d = queue.get() self.assertFailure(d, defer.CancelledError) d.cancel() def cb(ignore): # If the deferred is still linked with the deferred queue, it will # fail with an AlreadyCalledError queue.put(None) return queue.get().addCallback(self.assertIdentical, None) return d.addCallback(cb)
Example #2
Source File: ftp.py From python-for-android with Apache License 2.0 | 6 votes |
def _fail(self, error): """ Errback all queued deferreds. """ if self._failed: # We're recursing; bail out here for simplicity return error self._failed = 1 if self.nextDeferred: try: self.nextDeferred.errback(failure.Failure(ConnectionLost('FTP connection lost', error))) except defer.AlreadyCalledError: pass for ftpCommand in self.actionQueue: ftpCommand.fail(failure.Failure(ConnectionLost('FTP connection lost', error))) return error
Example #3
Source File: test_defer.py From learn_python3_spider with MIT License | 6 votes |
def test_cancelQueueAfterGet(self): """ When canceling a L{Deferred} from a L{DeferredQueue} that does not have a result (i.e., the L{Deferred} has not fired), the cancel causes a L{defer.CancelledError} failure. If the queue has a result later on, it doesn't try to fire the deferred. """ queue = defer.DeferredQueue() d = queue.get() d.cancel() self.assertImmediateFailure(d, defer.CancelledError) def cb(ignore): # If the deferred is still linked with the deferred queue, it will # fail with an AlreadyCalledError queue.put(None) return queue.get().addCallback(self.assertIs, None) d.addCallback(cb) done = [] d.addCallback(done.append) self.assertEqual(len(done), 1)
Example #4
Source File: test_defer.py From learn_python3_spider with MIT License | 6 votes |
def test_simpleCanceller(self): """ Verify that a L{defer.Deferred} calls its specified canceller when it is cancelled, and that further call/errbacks raise L{defer.AlreadyCalledError}. """ def cancel(d): self.cancellerCallCount += 1 d = defer.Deferred(canceller=cancel) d.addCallbacks(self._callback, self._errback) d.cancel() self.assertEqual(self.cancellerCallCount, 1) self.assertEqual(self.errbackResults.type, defer.CancelledError) # Test that further call/errbacks are *not* swallowed self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #5
Source File: test_defer.py From learn_python3_spider with MIT License | 6 votes |
def test_raisesAfterCancelAndErrback(self): """ A L{defer.Deferred} without a canceller, when cancelled must allow a single extra call to errback, and raise L{defer.AlreadyCalledError} if callbacked or errbacked thereafter. """ d = defer.Deferred() d.addCallbacks(self._callback, self._errback) d.cancel() # A single extra errback should be swallowed. d.errback(Exception()) # But a second call to callback or errback is not. self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #6
Source File: ftp.py From learn_python3_spider with MIT License | 6 votes |
def _fail(self, error): """ Errback all queued deferreds. """ if self._failed: # We're recursing; bail out here for simplicity return error self._failed = 1 if self.nextDeferred: try: self.nextDeferred.errback(failure.Failure(ConnectionLost('FTP connection lost', error))) except defer.AlreadyCalledError: pass for ftpCommand in self.actionQueue: ftpCommand.fail(failure.Failure(ConnectionLost('FTP connection lost', error))) return error
Example #7
Source File: test_defer.py From python-for-android with Apache License 2.0 | 6 votes |
def test_raisesAfterCancelAndErrback(self): """ A L{defer.Deferred} without a canceller, when cancelled must allow a single extra call to errback, and raise L{defer.AlreadyCalledError} if callbacked or errbacked thereafter. """ d = defer.Deferred() d.addCallbacks(self._callback, self._errback) d.cancel() # A single extra errback should be swallowed. d.errback(Exception()) # But a second call to callback or errback is not. self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #8
Source File: test_defer.py From python-for-android with Apache License 2.0 | 6 votes |
def test_simpleCanceller(self): """ Verify that a L{defer.Deferred} calls its specified canceller when it is cancelled, and that further call/errbacks raise L{defer.AlreadyCalledError}. """ def cancel(d): self.cancellerCallCount += 1 d = defer.Deferred(canceller=cancel) d.addCallbacks(self._callback, self._errback) d.cancel() self.assertEquals(self.cancellerCallCount, 1) self.assertEquals(self.errbackResults.type, defer.CancelledError) # Test that further call/errbacks are *not* swallowed self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #9
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_cancelQueueAfterGet(self): """ When canceling a L{Deferred} from a L{DeferredQueue} that does not have a result (i.e., the L{Deferred} has not fired), the cancel causes a L{defer.CancelledError} failure. If the queue has a result later on, it doesn't try to fire the deferred. """ queue = defer.DeferredQueue() d = queue.get() d.cancel() self.assertImmediateFailure(d, defer.CancelledError) def cb(ignore): # If the deferred is still linked with the deferred queue, it will # fail with an AlreadyCalledError queue.put(None) return queue.get().addCallback(self.assertIs, None) d.addCallback(cb) done = [] d.addCallback(done.append) self.assertEqual(len(done), 1)
Example #10
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_simpleCanceller(self): """ Verify that a L{defer.Deferred} calls its specified canceller when it is cancelled, and that further call/errbacks raise L{defer.AlreadyCalledError}. """ def cancel(d): self.cancellerCallCount += 1 d = defer.Deferred(canceller=cancel) d.addCallbacks(self._callback, self._errback) d.cancel() self.assertEqual(self.cancellerCallCount, 1) self.assertEqual(self.errbackResults.type, defer.CancelledError) # Test that further call/errbacks are *not* swallowed self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #11
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_raisesAfterCancelAndErrback(self): """ A L{defer.Deferred} without a canceller, when cancelled must allow a single extra call to errback, and raise L{defer.AlreadyCalledError} if callbacked or errbacked thereafter. """ d = defer.Deferred() d.addCallbacks(self._callback, self._errback) d.cancel() # A single extra errback should be swallowed. d.errback(Exception()) # But a second call to callback or errback is not. self.assertRaises(defer.AlreadyCalledError, d.callback, None) self.assertRaises(defer.AlreadyCalledError, d.errback, Exception())
Example #12
Source File: config.py From bitmask-dev with GNU General Public License v3.0 | 6 votes |
def maybe_download_services_config(self, ignored): # TODO --- currently, some providers (mail.bitmask.net) raise 401 # UNAUTHENTICATED if we try to get the services # See: # https://leap.se/code/issues/7906 def first_bootstrap_done(ignored): try: self.first_bootstrap.callback('got config') except defer.AlreadyCalledError: pass uri, met, path = self._get_configs_download_params() d = httpRequest( self._http._agent, uri, method=met, saveto=path) d.addCallback(lambda _: self._load_provider_json()) d.addCallback( lambda _: self._get_config_for_all_services(session=None)) d.addCallback(first_bootstrap_done) d.addErrback(lambda _: 'ok for now') return d
Example #13
Source File: config.py From bitmask-dev with GNU General Public License v3.0 | 6 votes |
def bootstrap(self, replace_if_newer=False): domain = self._domain self.log.debug('Bootstrapping provider %s' % domain) def first_bootstrap_done(ignored): if self._allows_anonymous(): # we continue bootstrapping, we do not # need to wait for authentication. return try: self.first_bootstrap.callback('got config') except defer.AlreadyCalledError: pass def first_bootstrap_error(failure): self.first_bootstrap.errback(failure) return failure d = self.maybe_download_provider_info(replace=replace_if_newer) d.addCallback(self.maybe_download_ca_cert, replace_if_newer) d.addCallback(self.validate_ca_cert) d.addCallbacks(first_bootstrap_done, first_bootstrap_error) d.addCallback(self.maybe_download_services_config) self.ongoing_bootstrap = d
Example #14
Source File: ftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _fail(self, error): """ Errback all queued deferreds. """ if self._failed: # We're recursing; bail out here for simplicity return error self._failed = 1 if self.nextDeferred: try: self.nextDeferred.errback(failure.Failure(ConnectionLost('FTP connection lost', error))) except defer.AlreadyCalledError: pass for ftpCommand in self.actionQueue: ftpCommand.fail(failure.Failure(ConnectionLost('FTP connection lost', error))) return error
Example #15
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalledDebug_EC(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) try: self._call_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_EC", "_err_1", "_call_2")
Example #16
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalledDebug_EE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) try: self._err_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_EE", "_err_1", "_err_2")
Example #17
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalled_CC(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._call_2, d)
Example #18
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalled_CE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._err_2, d)
Example #19
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalled_EE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._err_2, d)
Example #20
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalledDebug_CC(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) try: self._call_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_CC", "_call_1", "_call_2")
Example #21
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalledDebug_CE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) try: self._err_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_CE", "_call_1", "_err_2")
Example #22
Source File: unittest.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _run(self, methodName, result): from twisted.internet import reactor timeout = self.getTimeout() def onTimeout(d): e = defer.TimeoutError("%r (%s) still running at %s secs" % (self, methodName, timeout)) f = failure.Failure(e) # try to errback the deferred that the test returns (for no gorram # reason) (see issue1005 and test_errorPropagation in test_deferred) try: d.errback(f) except defer.AlreadyCalledError: # if the deferred has been called already but the *back chain is # still unfinished, crash the reactor and report timeout error # ourself. reactor.crash() self._timedOut = True # see self._wait todo = self.getTodo() if todo is not None and todo.expected(f): result.addExpectedFailure(self, f, todo) else: result.addError(self, f) if self._shared: test = self.__class__._testCaseInstance else: test = self method = getattr(test, methodName) d = defer.maybeDeferred(utils.runWithWarningsSuppressed, self.getSuppress(), method) call = reactor.callLater(timeout, onTimeout, d) d.addBoth(lambda x : call.active() and call.cancel() or x) return d
Example #23
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testAlreadyCalledDebug_EE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) try: self._err_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_EE", "_err_1", "_err_2")
Example #24
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
def testNoDebugging(self): defer.setDebugging(False) d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) try: self._call_2(d) except defer.AlreadyCalledError, e: self.failIf(e.args)
Example #25
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalledDebug_EC(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) try: self._call_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_EC", "_err_1", "_call_2")
Example #26
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalledDebug_CE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) try: self._err_2(d) except defer.AlreadyCalledError, e: self._check(e, "testAlreadyCalledDebug_CE", "_call_1", "_err_2")
Example #27
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalled_EC(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._call_2, d)
Example #28
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testNoDebugging(self): defer.setDebugging(False) d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) try: self._call_2(d) except defer.AlreadyCalledError, e: self.failIf(e.args)
Example #29
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalled_EE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._err_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._err_2, d)
Example #30
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testAlreadyCalled_CE(self): d = defer.Deferred() d.addCallbacks(self._callback, self._errback) self._call_1(d) self.failUnlessRaises(defer.AlreadyCalledError, self._err_2, d)