Python twisted.web.client 模块,PartialDownloadError() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用twisted.web.client.PartialDownloadError()

项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_withPotentialDataLoss(self):
        """
        If the full body of the L{IResponse} passed to L{client.readBody} is
        not definitely received, the L{Deferred} returned by L{client.readBody}
        fires with a L{Failure} wrapping L{client.PartialDownloadError} with
        the content that was received.
        """
        response = DummyResponse()
        d = client.readBody(response)
        response.protocol.dataReceived(b"first")
        response.protocol.dataReceived(b"second")
        response.protocol.connectionLost(Failure(PotentialDataLoss()))
        failure = self.failureResultOf(d)
        failure.trap(client.PartialDownloadError)
        self.assertEqual({
            "status": failure.value.status,
            "message": failure.value.message,
            "body": failure.value.response,
        }, {
            "status": b"200",
            "message": b"OK",
            "body": b"firstsecond",
        })
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_downloadPageBrokenDownload(self):
        """
        If the connection is closed before the number of bytes indicated by
        I{Content-Length} have been received, the L{Deferred} returned by
        L{downloadPage} fails with L{PartialDownloadError}.
        """
        # test what happens when download gets disconnected in the middle
        path = FilePath(self.mktemp())
        d = client.downloadPage(self.getURL("broken"), path.path)
        d = self.assertFailure(d, client.PartialDownloadError)

        def checkResponse(response):
            """
            The HTTP status code from the server is propagated through the
            C{PartialDownloadError}.
            """
            self.assertEqual(response.status, b"200")
            self.assertEqual(response.message, b"OK")
            return response
        d.addCallback(checkResponse)

        def cbFailed(ignored):
            self.assertEqual(path.getContent(), b"abc")
        d.addCallback(cbFailed)
        return d
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_downloadPageLogsFileCloseError(self):
        """
        If there is an exception closing the file being written to after the
        connection is prematurely closed, that exception is logged.
        """
        class BrokenFile:
            def write(self, bytes):
                pass

            def close(self):
                raise IOError(ENOSPC, "No file left on device")

        d = client.downloadPage(self.getURL("broken"), BrokenFile())
        d = self.assertFailure(d, client.PartialDownloadError)
        def cbFailed(ignored):
            self.assertEqual(len(self.flushLoggedErrors(IOError)), 1)
        d.addCallback(cbFailed)
        return d
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def testBrokenDownload(self):
        # test what happens when download gets disconnected in the middle
        d = client.getPage(self.getURL("broken"))
        d = self.assertFailure(d, client.PartialDownloadError)
        d.addCallback(lambda exc: self.assertEquals(exc.response, "abc"))
        return d
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def testBrokenDownload(self):
        # test what happens when download gets disconnected in the middle
        d = client.getPage(self.getURL("broken"))
        d = self.assertFailure(d, client.PartialDownloadError)
        d.addCallback(lambda exc: self.assertEquals(exc.response, "abc"))
        return d
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_getPageBrokenDownload(self):
        """
        If the connection is closed before the number of bytes indicated by
        I{Content-Length} have been received, the L{Deferred} returned by
        L{getPage} fails with L{PartialDownloadError}.
        """
        d = client.getPage(self.getURL("broken"))
        d = self.assertFailure(d, client.PartialDownloadError)
        d.addCallback(lambda exc: self.assertEqual(exc.response, b"abc"))
        return d
项目:ooniprobe-debian    作者:TheTorProject    | 项目源码 | 文件源码
def _processResponseBodyFail(self, failure, request, response):
        if failure.check(PartialDownloadError):
            return failure.value.response
        failure_string = handleAllFailures(failure)
        HTTPTest.addToReport(self, request, response,
                             failure_string=failure_string)
        return response
项目:enigma2-plugins    作者:opendreambox    | 项目源码 | 文件源码
def _onRequestBodyError(self, failure):
        if self._canceled:
            Log.d("Auth Request canceled")
            return
        if isinstance(failure.value, PartialDownloadError):
            self._onRequestBodyReady(failure.value.response)
        else:
            self._onError(self.ERROR_AUTH_REQUEST, str(failure))
项目:enigma2-plugins    作者:opendreambox    | 项目源码 | 文件源码
def _onCredentialsPollBodyError(self, failure):
        if self._canceled:
            Log.d("Auth Request canceled")
            return
        if isinstance(failure.value, PartialDownloadError):
            self._onCredentialsPollBodyReady(failure.value.response)
        else:
            self._onError(self.ERROR_CREDENTIALS_REQUEST_PARSE, str(failure))