本文整理汇总了Python中twisted.internet.defer.AlreadyCalledError方法的典型用法代码示例。如果您正苦于以下问题:Python defer.AlreadyCalledError方法的具体用法?Python defer.AlreadyCalledError怎么用?Python defer.AlreadyCalledError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.defer
的用法示例。
在下文中一共展示了defer.AlreadyCalledError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrap
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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
示例2: maybe_download_services_config
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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
示例3: _fail
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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
示例4: test_raisesAfterCancelAndErrback
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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())
示例5: test_simpleCanceller
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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())
示例6: test_cancelQueueAfterGet
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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)
示例7: test_simpleCanceller
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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())
示例8: test_cancelQueueAfterGet
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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)
示例9: _run
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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)
onTimeout = utils.suppressWarnings(
onTimeout, util.suppress(category=DeprecationWarning))
method = getattr(self, methodName)
if inspect.isgeneratorfunction(method):
exc = TypeError(
'%r is a generator function and therefore will never run' % (
method,))
return defer.fail(exc)
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
示例10: testAlreadyCalled_CC
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
def testAlreadyCalled_CC(self):
d = defer.Deferred()
d.addCallbacks(self._callback, self._errback)
self._call_1(d)
self.assertRaises(defer.AlreadyCalledError, self._call_2, d)
示例11: testAlreadyCalled_CE
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
def testAlreadyCalled_CE(self):
d = defer.Deferred()
d.addCallbacks(self._callback, self._errback)
self._call_1(d)
self.assertRaises(defer.AlreadyCalledError, self._err_2, d)
示例12: testAlreadyCalled_EE
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
def testAlreadyCalled_EE(self):
d = defer.Deferred()
d.addCallbacks(self._callback, self._errback)
self._err_1(d)
self.assertRaises(defer.AlreadyCalledError, self._err_2, d)
示例13: testAlreadyCalledDebug_CC
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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 as e:
self._check(e, "testAlreadyCalledDebug_CC", "_call_1", "_call_2")
else:
self.fail("second callback failed to raise AlreadyCalledError")
示例14: testAlreadyCalledDebug_CE
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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 as e:
self._check(e, "testAlreadyCalledDebug_CE", "_call_1", "_err_2")
else:
self.fail("second errback failed to raise AlreadyCalledError")
示例15: testAlreadyCalledDebug_EC
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import AlreadyCalledError [as 别名]
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 as e:
self._check(e, "testAlreadyCalledDebug_EC", "_err_1", "_call_2")
else:
self.fail("second callback failed to raise AlreadyCalledError")