当前位置: 首页>>代码示例>>Python>>正文


Python error.ConnectionLost方法代码示例

本文整理汇总了Python中twisted.internet.error.ConnectionLost方法的典型用法代码示例。如果您正苦于以下问题:Python error.ConnectionLost方法的具体用法?Python error.ConnectionLost怎么用?Python error.ConnectionLost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.ConnectionLost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connectionLost

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_connectionLost(self):
        """
        L{http.Request.connectionLost} closes L{Request.content} and drops the
        reference to the L{HTTPChannel} to assist with garbage collection.
        """
        req = http.Request(DummyChannel(), False)

        # Cause Request.content to be created at all.
        req.gotLength(10)

        # Grab a reference to content in case the Request drops it later on.
        content = req.content

        # Put some bytes into it
        req.handleContentChunk(b"hello")

        # Then something goes wrong and content should get closed.
        req.connectionLost(Failure(ConnectionLost("Finished")))
        self.assertTrue(content.closed)
        self.assertIdentical(req.channel, None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_http.py

示例2: test_someResponseButNotAll

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_someResponseButNotAll(self):
        """
        If a partial response was received and the connection is lost, the
        resulting error is L{ResponseFailed}, but not
        L{ResponseNeverReceived}.
        """
        protocol = HTTPClientParser(
            Request(b'HEAD', b'/', _boringHeaders, None),
            lambda ign: None)
        d = protocol._responseDeferred

        protocol.makeConnection(StringTransport())
        protocol.dataReceived(b'2')
        protocol.connectionLost(ConnectionLost())
        return self.assertFailure(d, ResponseFailed).addCallback(
            self.assertIsInstance, ResponseFailed) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_newclient.py

示例3: _disconnectSelectable

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:posixbase.py

示例4: test_unexpectedEOF

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_unexpectedEOF(self):
        """
        Unexpected disconnects get converted to ConnectionLost errors.
        """
        tlsClient, tlsServer, handshakeDeferred, disconnectDeferred = (
            self.handshakeProtocols())
        serverProtocol = tlsServer.wrappedProtocol
        data = []
        reason = []
        serverProtocol.dataReceived = data.append
        serverProtocol.connectionLost = reason.append

        # Write data, then disconnect *underlying* transport, resulting in an
        # unexpected TLS disconnect:
        def handshakeDone(ign):
            tlsClient.write(b"hello")
            tlsClient.transport.loseConnection()
        handshakeDeferred.addCallback(handshakeDone)

        # Receiver should be disconnected, with ConnectionLost notification
        # (masking the Unexpected EOF SSL error):
        def disconnected(ign):
            self.assertTrue(reason[0].check(ConnectionLost), reason[0])
        disconnectDeferred.addCallback(disconnected)
        return disconnectDeferred 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_tls.py

示例5: _cbLostConns

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def _cbLostConns(self, results):
        (sSuccess, sResult), (cSuccess, cResult) = results

        self.assertFalse(sSuccess)
        self.assertFalse(cSuccess)

        acceptableErrors = [SSL.Error]

        # Rather than getting a verification failure on Windows, we are getting
        # a connection failure.  Without something like sslverify proxying
        # in-between we can't fix up the platform's errors, so let's just
        # specifically say it is only OK in this one case to keep the tests
        # passing.  Normally we'd like to be as strict as possible here, so
        # we're not going to allow this to report errors incorrectly on any
        # other platforms.

        if platform.isWindows():
            from twisted.internet.error import ConnectionLost
            acceptableErrors.append(ConnectionLost)

        sResult.trap(*acceptableErrors)
        cResult.trap(*acceptableErrors)

        return self.serverPort.stopListening() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_ssl.py

示例6: _handleRead

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def _handleRead(self, rc, data, evt):
        """
        Returns False if we should stop reading for now
        """
        if self.disconnected:
            return False
        # graceful disconnection
        if (not (rc or data)) or rc in (errno.WSAEDISCON, ERROR_HANDLE_EOF):
            self.reactor.removeActiveHandle(self)
            self.readConnectionLost(failure.Failure(main.CONNECTION_DONE))
            return False
        # XXX: not handling WSAEWOULDBLOCK
        # ("too many outstanding overlapped I/O requests")
        elif rc:
            self.connectionLost(failure.Failure(
                                error.ConnectionLost("read error -- %s (%s)" %
                                    (errno.errorcode.get(rc, 'unknown'), rc))))
            return False
        else:
            assert self._readSize == 0
            assert self._readNextBuffer == 0
            self._readSize = data
            return self._dispatchData() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:25,代码来源:abstract.py

示例7: sendBox

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def sendBox(self, box):
        """
        Send a amp.Box to my peer.

        Note: transport.write is never called outside of this method.

        @param box: an AmpBox.

        @raise ProtocolSwitched: if the protocol has previously been switched.

        @raise ConnectionLost: if the connection has previously been lost.
        """
        if self._locked:
            raise ProtocolSwitched(
                "This connection has switched: no AMP traffic allowed.")
        if self.transport is None:
            raise ConnectionLost()
        if self._startingTLSBuffer is not None:
            self._startingTLSBuffer.append(box)
        else:
            self.transport.write(box.serialize()) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:amp.py

示例8: _invoke_callback

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def _invoke_callback(self, fd, events):
        (reader, writer) = self._fds[fd]
        if reader:
            err = None
            if reader.fileno() == -1:
                err = error.ConnectionLost()
            elif events & IOLoop.READ:
                err = log.callWithLogger(reader, reader.doRead)
            if err is None and events & IOLoop.ERROR:
                err = error.ConnectionLost()
            if err is not None:
                self.removeReader(reader)
                reader.readConnectionLost(failure.Failure(err))
        if writer:
            err = None
            if writer.fileno() == -1:
                err = error.ConnectionLost()
            elif events & IOLoop.WRITE:
                err = log.callWithLogger(writer, writer.doWrite)
            if err is None and events & IOLoop.ERROR:
                err = error.ConnectionLost()
            if err is not None:
                self.removeWriter(writer)
                writer.writeConnectionLost(failure.Failure(err)) 
开发者ID:omererdem,项目名称:honeything,代码行数:26,代码来源:twisted.py

示例9: stopProducing

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def stopProducing(self, failure=ti_error.ConnectionLost()):
        if self.consumer is not None:
            self.consumer.unregisterProducer()
        if self.finishedCallback is not None:
            if failure is not None:
                self.finishedCallback.errback(failure)
            else:
                self.finishedCallback.callback(None)
            self.finishedCallback = None
        self.paused = True
        if self.stream is not None:
            self.stream.close()

        self.finishedCallback = self.deferred = self.consumer = self.stream = None


#
# ProcessStreamer
# 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:21,代码来源:stream.py

示例10: _invoke_callback

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def _invoke_callback(self, fd, events):
        if fd not in self._fds:
            return
        (reader, writer) = self._fds[fd]
        if reader:
            err = None
            if reader.fileno() == -1:
                err = error.ConnectionLost()
            elif events & IOLoop.READ:
                err = log.callWithLogger(reader, reader.doRead)
            if err is None and events & IOLoop.ERROR:
                err = error.ConnectionLost()
            if err is not None:
                self.removeReader(reader)
                reader.readConnectionLost(failure.Failure(err))
        if writer:
            err = None
            if writer.fileno() == -1:
                err = error.ConnectionLost()
            elif events & IOLoop.WRITE:
                err = log.callWithLogger(writer, writer.doWrite)
            if err is None and events & IOLoop.ERROR:
                err = error.ConnectionLost()
            if err is not None:
                self.removeWriter(writer)
                writer.writeConnectionLost(failure.Failure(err)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:twisted.py

示例11: test_disconnected

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_disconnected(self):
        """
        Pending and future requests fail when the connection goes away.
        """
        d = self.protocol.request(b'api corr stuff')
        self.assertNoResult(d)

        self.transport.disconnectReason = ConnectionLost('Bye.')
        self.transport.reportDisconnect()
        self.failureResultOf(d, ConnectionLost)

        self.failureResultOf(self.protocol.request(b'api corr more'), ConnectionLost) 
开发者ID:ciena,项目名称:afkak,代码行数:14,代码来源:test_protocol.py

示例12: test_connectionClosedDuringIteration

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_connectionClosedDuringIteration(self):
        """
        If the request connection is lost while the application object is being
        iterated, iteration is stopped.
        """
        class UnreliableConnection(Request):
            """
            This is a request which pretends its connection is lost immediately
            after the first write is done to it.
            """
            def write(self, bytes):
                self.connectionLost(Failure(ConnectionLost("No more connection")))

        self.badIter = False
        def appIter():
            yield b"foo"
            self.badIter = True
            raise Exception("Should not have gotten here")

        def applicationFactory():
            def application(environ, startResponse):
                startResponse('200 OK', [])
                return appIter()
            return application

        d, requestFactory = self.requestFactoryFactory(UnreliableConnection)
        def cbRendered(ignored):
            self.assertFalse(self.badIter, "Should not have resumed iteration")
        d.addCallback(cbRendered)

        self.lowLevelRender(
            requestFactory, applicationFactory, DummyChannel,
            'GET', '1.1', [], [''])

        return self.assertFailure(d, ConnectionLost) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:37,代码来源:test_wsgi.py

示例13: _connectionClosedTest

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def _connectionClosedTest(self, application, responseContent):
        channel = DummyChannel()

        def applicationFactory():
            return application

        d, requestFactory = self.requestFactoryFactory()

        # Capture the request so we can disconnect it later on.
        requests = []
        def requestFactoryWrapper(*a, **kw):
            requests.append(requestFactory(*a, **kw))
            return requests[-1]

        def ebRendered(ignored):
            errors = self.flushLoggedErrors(RuntimeError)
            self.assertEqual(len(errors), 1)

            response = channel.transport.written.getvalue()
            self.assertTrue(response.startswith(b'HTTP/1.1 200 OK'))
            # Chunked transfer-encoding makes this a little messy.
            self.assertIn(responseContent, response)
        d.addErrback(ebRendered)

        self.lowLevelRender(
            requestFactoryWrapper, applicationFactory,
            lambda: channel, 'GET', '1.1', [], [''], None, [])

        # By now the connection should be closed.
        self.assertTrue(channel.transport.disconnected)
        # Give it a little push to go the rest of the way.
        requests[0].connectionLost(Failure(ConnectionLost("All gone")))

        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:test_wsgi.py

示例14: test_otherErrors

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_otherErrors(self):
        """
        If there is an exception other than L{client.PotentialDataLoss} while
        L{client.readBody} is collecting the response body, the L{Deferred}
        returned by {client.readBody} fires with that exception.
        """
        response = DummyResponse()
        d = client.readBody(response)
        response.protocol.dataReceived(b"first")
        response.protocol.connectionLost(
            Failure(ConnectionLost("mystery problem")))
        reason = self.failureResultOf(d)
        reason.trap(ConnectionLost)
        self.assertEqual(reason.value.args, ("mystery problem",)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_agent.py

示例15: test_connectionLostNotification

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ConnectionLost [as 别名]
def test_connectionLostNotification(self):
        """
        L{Request.connectionLost} triggers all finish notification Deferreds
        and cleans up per-request state.
        """
        d = DummyChannel()
        request = http.Request(d, True)
        finished = request.notifyFinish()
        request.connectionLost(Failure(ConnectionLost("Connection done")))
        self.assertIdentical(request.channel, None)
        return self.assertFailure(finished, ConnectionLost) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_http.py


注:本文中的twisted.internet.error.ConnectionLost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。