本文整理匯總了Python中twisted.internet.error.ConnectionDone方法的典型用法代碼示例。如果您正苦於以下問題:Python error.ConnectionDone方法的具體用法?Python error.ConnectionDone怎麽用?Python error.ConnectionDone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.error
的用法示例。
在下文中一共展示了error.ConnectionDone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_failedWriteTo
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_failedWriteTo(self):
"""
If the L{Deferred} returned by L{Request.writeTo} fires with a
L{Failure}, L{HTTP11ClientProtocol.request} disconnects its transport
and returns a L{Deferred} which fires with a L{Failure} of
L{RequestGenerationFailed} wrapping the underlying failure.
"""
class BrokenRequest:
persistent = False
def writeTo(self, transport):
return fail(ArbitraryException())
d = self.protocol.request(BrokenRequest())
def cbFailed(ignored):
self.assertTrue(self.transport.disconnecting)
# Simulate what would happen if the protocol had a real transport
# and make sure no exception is raised.
self.protocol.connectionLost(
Failure(ConnectionDone(u"you asked for it")))
d = assertRequestGenerationFailed(self, d, [ArbitraryException])
d.addCallback(cbFailed)
return d
示例2: test_parserDataReceivedException
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_parserDataReceivedException(self):
"""
If the parser L{HTTP11ClientProtocol} delivers bytes to in
C{dataReceived} raises an exception, the exception is wrapped in a
L{Failure} and passed to the parser's C{connectionLost} and then the
L{HTTP11ClientProtocol}'s transport is disconnected.
"""
requestDeferred = self.protocol.request(Request(b'GET', b'/',
_boringHeaders, None))
self.protocol.dataReceived(b'unparseable garbage goes here\r\n')
d = assertResponseFailed(self, requestDeferred, [ParseError])
def cbFailed(exc):
self.assertTrue(self.transport.disconnecting)
self.assertEqual(
exc.reasons[0].value.data, b'unparseable garbage goes here')
# Now do what StringTransport doesn't do but a real transport would
# have, call connectionLost on the HTTP11ClientProtocol. Nothing
# is asserted about this, but it's important for it to not raise an
# exception.
self.protocol.connectionLost(Failure(ConnectionDone(u"it is done")))
d.addCallback(cbFailed)
return d
示例3: _disconnectSelectable
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def _disconnectSelectable(self, selectable, why, isRead, faildict={
error.ConnectionDone: failure.Failure(error.ConnectionDone()),
error.ConnectionLost: failure.Failure(error.ConnectionLost())
}):
"""
Utility function for disconnecting a selectable.
Supports half-close notification, isRead should be boolean indicating
whether error resulted from doRead().
"""
self.removeReader(selectable)
f = faildict.get(why.__class__)
if f:
if (isRead and why.__class__ == error.ConnectionDone
and IHalfCloseableDescriptor.providedBy(selectable)):
selectable.readConnectionLost(f)
else:
self.removeWriter(selectable)
selectable.connectionLost(f)
else:
self.removeWriter(selectable)
selectable.connectionLost(failure.Failure(why))
示例4: test_processEnded
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_processEnded(self):
"""
L{LocalWorker.processEnded} calls C{connectionLost} on itself and on
the L{AMP} protocol.
"""
class FakeStream(object):
callNumber = 0
def close(self):
self.callNumber += 1
transport = FakeTransport()
protocol = FakeAMProtocol()
localWorker = LocalWorker(protocol, '.', 'test.log')
localWorker.makeConnection(transport)
localWorker._outLog = FakeStream()
localWorker.processEnded(Failure(CONNECTION_DONE))
self.assertEqual(localWorker._outLog.callNumber, 1)
self.assertIdentical(None, protocol.transport)
return self.assertFailure(localWorker.endDeferred, ConnectionDone)
示例5: _processConnectionError
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def _processConnectionError(self, connector, err):
self.currentProtocol = None
if (self.retries < 0) and (not self.sendFinished):
log.msg("SMTP Client retrying server. Retry: %s" % -self.retries)
# Rewind the file in case part of it was read while attempting to
# send the message.
self.file.seek(0, 0)
connector.connect()
self.retries += 1
elif not self.sendFinished:
# If we were unable to communicate with the SMTP server a ConnectionDone will be
# returned. We want a more clear error message for debugging
if err.check(error.ConnectionDone):
err.value = SMTPConnectError(-1, "Unable to connect to server.")
self.result.errback(err.value)
示例6: testPathelogicalScatteringOfLiterals
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def testPathelogicalScatteringOfLiterals(self):
self.server.checker.addUser(b'testuser', b'password-test')
transport = StringTransport()
self.server.makeConnection(transport)
transport.clear()
self.server.dataReceived(b"01 LOGIN {8}\r\n")
self.assertEqual(transport.value(), b"+ Ready for 8 octets of text\r\n")
transport.clear()
self.server.dataReceived(b"testuser {13}\r\n")
self.assertEqual(transport.value(), b"+ Ready for 13 octets of text\r\n")
transport.clear()
self.server.dataReceived(b"password-test\r\n")
self.assertEqual(transport.value(), b"01 OK LOGIN succeeded\r\n")
self.assertEqual(self.server.state, 'auth')
self.server.connectionLost(error.ConnectionDone("Connection done."))
示例7: test_fetchWithPartialValidArgument
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_fetchWithPartialValidArgument(self):
"""
If by any chance, extra bytes got appended at the end of a valid
FETCH arguments, the client should get a BAD - arguments invalid
response.
See U{RFC 3501<http://tools.ietf.org/html/rfc3501#section-6.4.5>},
section 6.4.5,
"""
# We need to clear out the welcome message.
self.transport.clear()
# Let's send out the faulty command.
self.server.dataReceived(b"0001 FETCH 1 FULLL\r\n")
expected = b"0001 BAD Illegal syntax: Invalid Argument\r\n"
self.assertEqual(self.transport.value(), expected)
self.transport.clear()
self.server.connectionLost(error.ConnectionDone("Connection closed"))
示例8: test_connectionClosedBeforeSecure
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_connectionClosedBeforeSecure(self):
"""
If the connection closes at any point before the SSH transport layer
has finished key exchange (ie, gotten to the point where we may attempt
to authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
the reason for the lost connection.
"""
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)
transport = StringTransport()
factory = self.reactor.tcpClients[0][2]
client = factory.buildProtocol(None)
client.makeConnection(transport)
client.connectionLost(Failure(ConnectionDone()))
self.failureResultOf(d).trap(ConnectionDone)
示例9: test_controlD
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_controlD(self):
"""
A CTRL+D in the middle of a line doesn't close a connection,
but at the beginning of a line it does.
"""
self._testwrite(b"1 + 1")
yield self.recvlineClient.expect(br"\+ 1")
self._assertBuffer([b">>> 1 + 1"])
self._testwrite(manhole.CTRL_D + b" + 1")
yield self.recvlineClient.expect(br"\+ 1")
self._assertBuffer([b">>> 1 + 1 + 1"])
self._testwrite(b"\n")
yield self.recvlineClient.expect(b"3\n>>> ")
self._testwrite(manhole.CTRL_D)
d = self.recvlineClient.onDisconnection
yield self.assertFailure(d, error.ConnectionDone)
示例10: test_wrapProtocol
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_wrapProtocol(self):
"""
L{wrapProtocol}, when passed a L{Protocol} should return something that
has write(), writeSequence(), loseConnection() methods which call the
Protocol's dataReceived() and connectionLost() methods, respectively.
"""
protocol = MockProtocol()
protocol.transport = StubTransport()
protocol.connectionMade()
wrapped = session.wrapProtocol(protocol)
wrapped.dataReceived(b'dataReceived')
self.assertEqual(protocol.transport.buf, b'dataReceived')
wrapped.write(b'data')
wrapped.writeSequence([b'1', b'2'])
wrapped.loseConnection()
self.assertEqual(protocol.data, b'data12')
protocol.reason.trap(error.ConnectionDone)
示例11: test_closePortInProtocolFactory
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_closePortInProtocolFactory(self):
"""
A port created with L{IReactorTCP.listenTCP} can be connected to with
L{IReactorTCP.connectTCP}.
"""
f = ClosingFactory()
port = reactor.listenTCP(0, f, interface="127.0.0.1")
f.port = port
self.addCleanup(f.cleanUp)
portNumber = port.getHost().port
clientF = MyClientFactory()
reactor.connectTCP("127.0.0.1", portNumber, clientF)
def check(x):
self.assertTrue(clientF.protocol.made)
self.assertTrue(port.disconnected)
clientF.lostReason.trap(error.ConnectionDone)
return clientF.deferred.addCallback(check)
示例12: test_timeOut
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_timeOut(self):
"""
Test the timeout on outgoing requests: when timeout is detected, all
current commands fail with a L{TimeoutError}, and the connection is
closed.
"""
d1 = self.proto.get(b"foo")
d2 = self.proto.get(b"bar")
d3 = Deferred()
self.proto.connectionLost = d3.callback
self.clock.advance(self.proto.persistentTimeOut)
self.assertFailure(d1, TimeoutError)
self.assertFailure(d2, TimeoutError)
def checkMessage(error):
self.assertEqual(str(error), "Connection timeout")
d1.addCallback(checkMessage)
self.assertFailure(d3, ConnectionDone)
return gatherResults([d1, d2, d3])
示例13: test_connectionLost
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def test_connectionLost(self):
"""
When disconnection occurs while commands are still outstanding, the
commands fail.
"""
d1 = self.proto.get(b"foo")
d2 = self.proto.get(b"bar")
self.transport.loseConnection()
done = DeferredList([d1, d2], consumeErrors=True)
def checkFailures(results):
for success, result in results:
self.assertFalse(success)
result.trap(ConnectionDone)
return done.addCallback(checkFailures)
示例14: make_capture_protocol
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def make_capture_protocol():
"""
Return a ``Deferred``, and a ``Protocol`` which will capture bytes and fire
the ``Deferred`` when its connection is lost.
:returns: A 2-tuple of ``Deferred`` and ``Protocol`` instance.
:rtype: tuple
"""
d = Deferred()
captured_data = []
class Recorder(Protocol):
def dataReceived(self, data):
captured_data.append(data)
def connectionLost(self, reason):
if reason.check(ConnectionDone):
d.callback(b''.join(captured_data))
else:
d.errback(reason)
return d, Recorder()
示例15: _response_err
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionDone [as 別名]
def _response_err(self, fail):
"""errBack for all exceptions that should be logged
This traps all exceptions to prevent any further callbacks from
running.
"""
from twisted.internet.error import ConnectionDone
fmt = str(fail.value) or 'Exception'
if isinstance(fail.value, ConnectionDone):
return
self.log.failure(format=fmt, failure=fail,
status_code=500, errno=999,
client_info=self._client_info)
self._write_response(500, 999, message="An unexpected server error"
" occurred.")