本文整理汇总了Python中twisted.internet.error.UserError方法的典型用法代码示例。如果您正苦于以下问题:Python error.UserError方法的具体用法?Python error.UserError怎么用?Python error.UserError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.error
的用法示例。
在下文中一共展示了error.UserError方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_userFail
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def test_userFail(self):
"""
Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
results in C{Factory.clientConnectionFailed} being called with
L{error.UserError} as the reason.
"""
serverFactory = MyServerFactory()
tcpPort = reactor.listenTCP(0, serverFactory, interface="127.0.0.1")
self.addCleanup(tcpPort.stopListening)
portNumber = tcpPort.getHost().port
def startedConnecting(connector):
connector.stopConnecting()
clientFactory = ClientStartStopFactory()
clientFactory.startedConnecting = startedConnecting
reactor.connectTCP("127.0.0.1", portNumber, clientFactory)
d = loopUntil(lambda: clientFactory.stopped)
def check(ignored):
self.assertEquals(clientFactory.failed, 1)
clientFactory.reason.trap(error.UserError)
return d.addCallback(check)
示例2: testUserFail
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def testUserFail(self):
f = MyServerFactory()
p = reactor.listenTCP(0, f, interface="127.0.0.1")
n = p.getHost().port
self.ports.append(p)
def startedConnecting(connector):
connector.stopConnecting()
factory = ClientStartStopFactory()
factory.startedConnecting = startedConnecting
reactor.connectTCP("127.0.0.1", n, factory)
d = loopUntil(lambda :factory.stopped)
def check(ignored):
self.assertEquals(factory.failed, 1)
factory.reason.trap(error.UserError)
return self.cleanPorts(*self.ports)
return d.addCallback(check)
示例3: test_client_close
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def test_client_close(self):
"""
close() terminates any outstanding broker connections, ignoring any
errors.
"""
reactor, connections, client = self.client_with_metadata(brokers=[
BrokerMetadata(1, 'kafka0', 9092),
BrokerMetadata(2, 'kafka2', 9092),
])
request_d = client.load_metadata_for_topics()
conn1 = connections.accept('kafka*')
reactor.advance(client.timeout) # Time out first attempt, try second broker.
self.assertNoResult(request_d)
conn2 = connections.accept('kafka*')
conn2.client.transport.disconnectReason = UserError()
close_d = client.close()
self.assertNoResult(close_d) # Waiting for connection shutdown.
connections.flush() # Complete connection shutdown.
self.assertIs(None, self.successResultOf(close_d))
self.assertTrue(conn1.server.transport.disconnected)
self.assertTrue(conn2.server.transport.disconnected)
# FIXME Afkak #71: The bootstrap retry loop leaves delayed calls (for timeouts)
# in the reactor.
self.assertEqual([], reactor.getDelayedCalls())
示例4: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
"""
If a connection attempt is still outstanding (i.e. no connection is
yet established), immediately stop attempting to connect.
"""
self.failIfNotConnected(error.UserError())
示例5: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
"""Stop attempting to connect."""
if self.state != "connecting":
raise error.NotConnectingError("we're not trying to connect")
self.state = "disconnected"
self.transport.failIfNotConnected(error.UserError())
del self.transport
示例6: test_endpointConnectingCancelled
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [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)
示例7: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
"""
Stop attempt to connect.
"""
self.failIfNotConnected(error.UserError())
示例8: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
"""Stop attempt to connect."""
self.failIfNotConnected(error.UserError())
示例9: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
"""Stop attempting to connect."""
if self.state != "connecting":
raise error.NotConnectingError, "we're not trying to connect"
self.state = "disconnected"
self.transport.failIfNotConnected(error.UserError())
del self.transport
示例10: _cancelled
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def _cancelled(self):
if not self.deferredResult.called:
self.deferredResult.errback(netError.UserError("User hit Cancel."))
self._loginDialog.destroy()
示例11: stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
if self._started:
self.connector.stopConnecting()
self._cleanup()
return
self.reactor.drop_postponed(self)
# for accuracy
self.factory.startedConnecting(self)
abort = failure.Failure(error.UserError(string="Connection preempted"))
self.factory.clientConnectionFailed(self, abort)
self._cleanup()
示例12: handle_connecting_stopConnecting
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def handle_connecting_stopConnecting(self):
self.connectionFailed(failure.Failure(error.UserError()))
示例13: _windowClosed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def _windowClosed(self, reason=None):
if not self.deferredResult.called:
self.deferredResult.errback(netError.UserError("Window closed."))