本文整理匯總了Python中twisted.internet.error.ConnectingCancelledError方法的典型用法代碼示例。如果您正苦於以下問題:Python error.ConnectingCancelledError方法的具體用法?Python error.ConnectingCancelledError怎麽用?Python error.ConnectingCancelledError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.error
的用法示例。
在下文中一共展示了error.ConnectingCancelledError方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _canceller
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def _canceller(self, deferred):
"""
The outgoing connection attempt was cancelled. Fail that L{Deferred}
with an L{error.ConnectingCancelledError}.
@param deferred: The L{Deferred <defer.Deferred>} that was cancelled;
should be the same as C{self._onConnection}.
@type deferred: L{Deferred <defer.Deferred>}
@note: This relies on startedConnecting having been called, so it may
seem as though there's a race condition where C{_connector} may not
have been set. However, using public APIs, this condition is
impossible to catch, because a connection API
(C{connectTCP}/C{SSL}/C{UNIX}) is always invoked before a
L{_WrappingFactory}'s L{Deferred <defer.Deferred>} is returned to
C{connect()}'s caller.
@return: L{None}
"""
deferred.errback(
error.ConnectingCancelledError(
self._connector.getDestination()))
self._connector.stopConnecting()
示例2: test_connectionCancelledBeforeConnected
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def test_connectionCancelledBeforeConnected(self):
"""
If the connection is cancelled before it finishes connecting, the
connection attempt is stopped.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
d.cancel()
self.failureResultOf(d).trap(ConnectingCancelledError)
self.assertTrue(self.reactor.connectors[0].stoppedConnecting)
示例3: connect
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def connect(self, protocolFactory):
"""
Implement L{IStreamClientEndpoint.connect} to connect via TCP.
"""
def _canceller(deferred):
connector.stopConnecting()
deferred.errback(
error.ConnectingCancelledError(connector.getDestination()))
try:
wf = _WrappingFactory(protocolFactory, _canceller)
connector = self._reactor.connectTCP(
self._host, self._port, wf,
timeout=self._timeout, bindAddress=self._bindAddress)
return wf._onConnection
except:
return defer.fail()
示例4: request_async
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def request_async(self, endpoint_name, endpoint_call_options, callback, cancellation_event):
def async_request(endpoint_call_options, cancellation_event, callback):
def manage_failures(failure):
# Cancelled
if failure.type == ConnectingCancelledError:
return
elif failure.type == PubNubTwistedException:
callback(failure.value)
else:
return failure
def options_func():
return endpoint_call_options
request = self.request_deferred(options_func, cancellation_event)
request.addCallbacks(callback, manage_failures)
self.reactor.callLater(0, async_request, endpoint_call_options, cancellation_event, callback)
return
# REVIEW: cancellation_event doesn't used inside function
示例5: test_endpointConnectingCancelled
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def test_endpointConnectingCancelled(self):
"""
Calling L{Deferred.cancel} on the L{Deferred} returned from
L{IStreamClientEndpoint.connect} is errbacked with an expected
L{ConnectingCancelledError} exception.
"""
mreactor = MemoryReactor()
clientFactory = object()
ep, ignoredArgs, address = self.createClientEndpoint(
mreactor, clientFactory)
d = ep.connect(clientFactory)
receivedFailures = []
def checkFailure(f):
receivedFailures.append(f)
d.addErrback(checkFailure)
d.cancel()
# When canceled, the connector will immediately notify its factory that
# the connection attempt has failed due to a UserError.
attemptFactory = self.retrieveConnectedFactory(mreactor)
attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
# This should be a feature of MemoryReactor: <http://tm.tl/5630>.
self.assertEqual(len(receivedFailures), 1)
failure = receivedFailures[0]
self.assertIsInstance(failure.value, error.ConnectingCancelledError)
self.assertEqual(failure.value.address, address)
示例6: test_endpointConnectingCancelledAfterAllAttemptsStarted
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def test_endpointConnectingCancelledAfterAllAttemptsStarted(self):
"""
Calling L{Deferred.cancel} on the L{Deferred} returned from
L{IStreamClientEndpoint.connect} after enough time has passed that all
connection attempts have been initiated will cause it to be errbacked
with a L{ConnectingCancelledError} exception.
"""
oneBetween = endpoints.HostnameEndpoint._DEFAULT_ATTEMPT_DELAY
advance = oneBetween + (oneBetween / 2.0)
self.test_endpointConnectingCancelled(advance=advance)
示例7: test_connectingCancelledError
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def test_connectingCancelledError(self):
"""
L{error.ConnectingCancelledError} has an C{address} attribute.
"""
address = object()
e = error.ConnectingCancelledError(address)
self.assertIs(e.address, address)
示例8: _schedule_connection
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def _schedule_connection(self, delay, h, is_relay):
ep = endpoint_from_hint_obj(h, self._tor, self._reactor)
desc = describe_hint_obj(h, is_relay, self._tor)
d = deferLater(self._reactor, delay,
self._connect, ep, desc, is_relay)
d.addErrback(lambda f: f.trap(ConnectingCancelledError,
ConnectionRefusedError,
CancelledError,
))
# TODO: HostnameEndpoint.connect catches CancelledError and replaces
# it with DNSLookupError. Remove this workaround when
# https://twistedmatrix.com/trac/ticket/9696 is fixed.
d.addErrback(lambda f: f.trap(DNSLookupError))
d.addErrback(log.err)
self._pending_connectors.add(d)
示例9: test_endpointConnectingCancelled
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def test_endpointConnectingCancelled(self):
"""
Calling L{Deferred.cancel} on the L{Deferred} returned from
L{IStreamClientEndpoint.connect} is errbacked with an expected
L{ConnectingCancelledError} exception.
"""
mreactor = MemoryReactor()
clientFactory = object()
ep, ignoredArgs, address = self.createClientEndpoint(
mreactor, clientFactory)
d = ep.connect(clientFactory)
receivedFailures = []
def checkFailure(f):
receivedFailures.append(f)
d.addErrback(checkFailure)
d.cancel()
self.assertEquals(len(receivedFailures), 1)
failure = receivedFailures[0]
self.assertIsInstance(failure.value, error.ConnectingCancelledError)
self.assertEquals(failure.value.address, address)
示例10: request
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectingCancelledError [as 別名]
def request(self, url, method='GET', headers={}, data=None, socket=None):
self.timedout = False
if socket:
agent = SocketyAgent(reactor, socket)
else:
if url[:5] == 'https':
if SSL:
agent = Agent(reactor, WebClientContextFactory())
else:
raise Exception('HTTPS requested but not supported')
else:
agent = Agent(reactor)
request = agent.request(method.encode(), url.encode(),
Headers(headers),
StringProducer(data) if data else None
)
if self.timeout:
timer = reactor.callLater(self.timeout, self.abort_request,
request)
def timeoutProxy(request):
if timer.active():
timer.cancel()
return self.response(request)
def requestAborted(failure):
if timer.active():
timer.cancel()
failure.trap(defer.CancelledError,
error.ConnectingCancelledError)
raise Timeout(
"Request took longer than %s seconds" % self.timeout)
request.addCallback(timeoutProxy).addErrback(requestAborted)
else:
request.addCallback(self.response)
return request