本文整理汇总了Python中twisted.internet.error.ConnectionClosed方法的典型用法代码示例。如果您正苦于以下问题:Python error.ConnectionClosed方法的具体用法?Python error.ConnectionClosed怎么用?Python error.ConnectionClosed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.error
的用法示例。
在下文中一共展示了error.ConnectionClosed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fileDescriptorOverrun
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_fileDescriptorOverrun(self):
"""
If L{IUNIXTransport.sendFileDescriptor} is used to queue a greater
number of file descriptors than the number of bytes sent using
L{ITransport.write}, the connection is closed and the protocol connected
to the transport has its C{connectionLost} method called with a failure
wrapping L{FileDescriptorOverrun}.
"""
cargo = socket()
server = SendFileDescriptor(cargo.fileno(), None)
client = ReceiveFileDescriptor()
result = []
d = client.waitForDescriptor()
d.addBoth(result.append)
d.addBoth(lambda ignored: server.transport.loseConnection())
runProtocolsWithReactor(self, server, client, self.endpoints)
self.assertIsInstance(result[0], Failure)
result[0].trap(ConnectionClosed)
self.assertIsInstance(server.reason.value, FileDescriptorOverrun)
示例2: connectionLost
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def connectionLost(self, reason):
"""
The connection was lost; notify any nested protocol.
"""
if self.innerProtocol is not None:
self.innerProtocol.connectionLost(reason)
if self.innerProtocolClientFactory is not None:
self.innerProtocolClientFactory.clientConnectionLost(None, reason)
if self._keyLengthLimitExceeded:
failReason = Failure(TooLong(True, False, None, None))
elif reason.check(ConnectionClosed) and self._justStartedTLS:
# We just started TLS and haven't received any data. This means
# the other connection didn't like our cert (although they may not
# have told us why - later Twisted should make 'reason' into a TLS
# error.)
failReason = PeerVerifyError(
"Peer rejected our certificate for an unknown reason.")
else:
failReason = reason
self.boxReceiver.stopReceivingBoxes(failReason)
# The longest key allowed
示例3: test_surpriseFromInfoCallback
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_surpriseFromInfoCallback(self):
"""
pyOpenSSL isn't always so great about reporting errors. If one occurs
in the verification info callback, it should be logged and the
connection should be shut down (if possible, anyway; the app_data could
be clobbered but there's no point testing for that).
"""
cProto, sProto, pump = self.serviceIdentitySetup(
u"correct-host.example.com",
u"correct-host.example.com",
buggyInfoCallback=True,
)
self.assertEqual(cProto.wrappedProtocol.data, b'')
self.assertEqual(sProto.wrappedProtocol.data, b'')
cErr = cProto.wrappedProtocol.lostReason.value
sErr = sProto.wrappedProtocol.lostReason.value
self.assertIsInstance(cErr, ZeroDivisionError)
self.assertIsInstance(sErr, (ConnectionClosed, SSL.Error))
errors = self.flushLoggedErrors(ZeroDivisionError)
self.assertTrue(errors)
示例4: test_invalidHostname
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_invalidHostname(self):
"""
When a certificate containing an invalid hostname is received from the
server, the connection is immediately dropped.
"""
cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup(
u"wrong-host.example.com",
u"correct-host.example.com",
)
self.assertEqual(cWrapped.data, b'')
self.assertEqual(sWrapped.data, b'')
cErr = cWrapped.lostReason.value
sErr = sWrapped.lostReason.value
self.assertIsInstance(cErr, VerificationError)
self.assertIsInstance(sErr, ConnectionClosed)
示例5: test_surpriseFromInfoCallback
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_surpriseFromInfoCallback(self):
"""
pyOpenSSL isn't always so great about reporting errors. If one occurs
in the verification info callback, it should be logged and the
connection should be shut down (if possible, anyway; the app_data could
be clobbered but there's no point testing for that).
"""
cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup(
u"correct-host.example.com",
u"correct-host.example.com",
buggyInfoCallback=True,
)
self.assertEqual(cWrapped.data, b'')
self.assertEqual(sWrapped.data, b'')
cErr = cWrapped.lostReason.value
sErr = sWrapped.lostReason.value
self.assertIsInstance(cErr, ZeroDivisionError)
self.assertIsInstance(sErr, (ConnectionClosed, SSL.Error))
errors = self.flushLoggedErrors(ZeroDivisionError)
self.assertTrue(errors)
示例6: handshakeFailed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def handshakeFailed(self, failure):
"""The authenticate handshake failed."""
if failure.check(ConnectionClosed):
# There has been a disconnection, clean or otherwise. There's
# nothing we can do now, so do nothing. The reason will have been
# logged elsewhere.
return
else:
log.msg(
"Rack controller '%s' could not be authenticated; dropping "
"connection. Check that /var/lib/maas/secret on the "
"controller contains the correct shared key." % self.ident
)
if self.transport is not None:
return self.transport.loseConnection()
else:
return
示例7: test_connectionLostSubclassOfConnectionClosed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_connectionLostSubclassOfConnectionClosed(self):
"""
L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
"""
self.assertTrue(issubclass(error.ConnectionLost,
error.ConnectionClosed))
示例8: test_connectionDoneSubclassOfConnectionClosed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_connectionDoneSubclassOfConnectionClosed(self):
"""
L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
"""
self.assertTrue(issubclass(error.ConnectionDone,
error.ConnectionClosed))
示例9: test_receive_queue
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_receive_queue(self):
c = transit.Connection(None, None, None, "description")
c.transport = FakeTransport(c, None)
c.transport.signalConnectionLost = False
c.recordReceived(b"0")
c.recordReceived(b"1")
c.recordReceived(b"2")
d0 = c.receive_record()
self.assertEqual(self.successResultOf(d0), b"0")
d1 = c.receive_record()
d2 = c.receive_record()
# they must fire in order of receipt, not order of addCallback
self.assertEqual(self.successResultOf(d2), b"2")
self.assertEqual(self.successResultOf(d1), b"1")
d3 = c.receive_record()
d4 = c.receive_record()
self.assertNoResult(d3)
self.assertNoResult(d4)
c.recordReceived(b"3")
self.assertEqual(self.successResultOf(d3), b"3")
self.assertNoResult(d4)
c.recordReceived(b"4")
self.assertEqual(self.successResultOf(d4), b"4")
d5 = c.receive_record()
c.close()
self.failureResultOf(d5, error.ConnectionClosed)
示例10: test_connectConsumer
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_connectConsumer(self):
# connectConsumer() takes an optional number of bytes to expect, and
# fires a Deferred when that many have been written
c = transit.Connection(None, None, None, "description")
c._negotiation_d.addErrback(lambda err: None) # eat it
c.transport = proto_helpers.StringTransport()
c.recordReceived(b"r1.")
consumer = proto_helpers.StringTransport()
d = c.connectConsumer(consumer, expected=10)
self.assertEqual(consumer.value(), b"r1.")
self.assertNoResult(d)
c.recordReceived(b"r2.")
self.assertEqual(consumer.value(), b"r1.r2.")
self.assertNoResult(d)
c.recordReceived(b"r3.")
self.assertEqual(consumer.value(), b"r1.r2.r3.")
self.assertNoResult(d)
c.recordReceived(b"!")
self.assertEqual(consumer.value(), b"r1.r2.r3.!")
self.assertEqual(self.successResultOf(d), 10)
# that should automatically disconnect the consumer, and subsequent
# records should get queued, not delivered
self.assertIs(c._consumer, None)
c.recordReceived(b"overflow")
self.assertEqual(consumer.value(), b"r1.r2.r3.!")
# now test that the Deferred errbacks when the connection is lost
d = c.connectConsumer(consumer, expected=10)
c.connectionLost()
self.failureResultOf(d, error.ConnectionClosed)
示例11: handshakeFailed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def handshakeFailed(self, failure):
"""The handshake (identify and authenticate) failed."""
if failure.check(ConnectionClosed):
# There has been a disconnection, clean or otherwise. There's
# nothing we can do now, so do nothing. The reason will have been
# logged elsewhere.
self.ready.fail(failure)
else:
log.err(
failure,
"Event-loop '%s' handshake failed; "
"dropping connection." % self.ident,
)
self.transport.loseConnection()
self.ready.fail(failure)
示例12: test_handshakeFailed_does_not_log_when_connection_is_closed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_handshakeFailed_does_not_log_when_connection_is_closed(self):
client = self.make_running_client()
with TwistedLoggerFixture() as logger:
client.handshakeFailed(Failure(ConnectionClosed()))
# ready was set with ConnectionClosed.
self.assertRaises(ConnectionClosed, extract_result, client.ready.get())
# Nothing was logged.
self.assertEqual("", logger.output)
示例13: test_handshakeFailed_does_not_log_when_connection_is_closed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_handshakeFailed_does_not_log_when_connection_is_closed(self):
server = RegionServer()
with TwistedLoggerFixture() as logger:
server.handshakeFailed(Failure(ConnectionClosed()))
# Nothing was logged.
self.assertEqual("", logger.output)
示例14: test_connection_closed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_connection_closed(test_client, mock_treq):
mock_treq.post.side_effect = ConnectionClosed()
output = yield test_client.request("POST", "/test/uri", SOME_JSON)
assert output == ConnectionClosed
示例15: test_properlyCloseFiles
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionClosed [as 别名]
def test_properlyCloseFiles(self):
"""
Test that lost connections properly have their underlying socket
resources cleaned up.
"""
onServerConnectionLost = defer.Deferred()
serverFactory = protocol.ServerFactory()
serverFactory.protocol = lambda: ConnectionLostNotifyingProtocol(
onServerConnectionLost)
serverPort = self.createServer('127.0.0.1', 0, serverFactory)
onClientConnectionLost = defer.Deferred()
serverAddr = serverPort.getHost()
clientCreator = protocol.ClientCreator(
reactor, lambda: HandleSavingProtocol(onClientConnectionLost))
clientDeferred = self.connectClient(
serverAddr.host, serverAddr.port, clientCreator)
def clientConnected(client):
"""
Disconnect the client. Return a Deferred which fires when both
the client and the server have received disconnect notification.
"""
client.transport.write(
b'some bytes to make sure the connection is set up')
client.transport.loseConnection()
return defer.gatherResults([
onClientConnectionLost, onServerConnectionLost])
clientDeferred.addCallback(clientConnected)
def clientDisconnected(result):
"""
Verify that the underlying platform socket handle has been
cleaned up.
"""
client, server = result
if not client.lostConnectionReason.check(error.ConnectionClosed):
err(client.lostConnectionReason,
"Client lost connection for unexpected reason")
if not server.lostConnectionReason.check(error.ConnectionClosed):
err(server.lostConnectionReason,
"Server lost connection for unexpected reason")
expectedErrorCode = self.getHandleErrorCode()
exception = self.assertRaises(
self.getHandleExceptionType(), client.handle.send, b'bytes')
self.assertEqual(exception.args[0], expectedErrorCode)
clientDeferred.addCallback(clientDisconnected)
def cleanup(passthrough):
"""
Shut down the server port. Return a Deferred which fires when
this has completed.
"""
result = defer.maybeDeferred(serverPort.stopListening)
result.addCallback(lambda ign: passthrough)
return result
clientDeferred.addBoth(cleanup)
return clientDeferred