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


Python client.PartialDownloadError方法代码示例

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


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

示例1: test_withPotentialDataLoss

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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",
        }) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_agent.py

示例2: test_downloadPageBrokenDownload

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

示例3: test_downloadPageLogsFileCloseError

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

示例4: test_downloadPageBrokenDownload

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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.assertEquals(response.status, "200")
            self.assertEquals(response.message, "OK")
            return response
        d.addCallback(checkResponse)

        def cbFailed(ignored):
            self.assertEquals(path.getContent(), "abc")
        d.addCallback(cbFailed)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_webclient.py

示例5: test_downloadPageLogsFileCloseError

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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.assertEquals(len(self.flushLoggedErrors(IOError)), 1)
        d.addCallback(cbFailed)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_webclient.py

示例6: test_delete_node_continues_on_404_error

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
def test_delete_node_continues_on_404_error(self):
        driver = RSDPodDriver()
        context = make_context()
        url = driver.get_url(context)
        node_id = context.get("node_id").encode("utf-8")
        endpoint = b"redfish/v1/Nodes/%s" % node_id
        headers = driver.make_auth_headers(**context)
        mock_redfish_request = self.patch(driver, "redfish_request")
        error = PartialDownloadError(
            response=json.dumps(SAMPLE_JSON_SYSTEMS).encode("utf-8"),
            code=HTTPStatus.NOT_FOUND,
        )
        mock_redfish_request.side_effect = error

        yield driver.delete_node(url, node_id, headers)
        self.assertThat(
            mock_redfish_request,
            MockCalledOnceWith(b"DELETE", join(url, endpoint), headers),
        ) 
开发者ID:maas,项目名称:maas,代码行数:21,代码来源:test_rsd.py

示例7: test_delete_node_raises_when_not_404_error

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
def test_delete_node_raises_when_not_404_error(self):
        driver = RSDPodDriver()
        context = make_context()
        url = driver.get_url(context)
        node_id = context.get("node_id").encode("utf-8")
        endpoint = b"redfish/v1/Nodes/%s" % node_id
        headers = driver.make_auth_headers(**context)
        mock_redfish_request = self.patch(driver, "redfish_request")
        error = PartialDownloadError(
            response=json.dumps(SAMPLE_JSON_SYSTEMS).encode("utf-8"),
            code=HTTPStatus.BAD_REQUEST,
        )
        mock_redfish_request.side_effect = error

        with ExpectedException(PartialDownloadError):
            yield driver.delete_node(url, node_id, headers)
        self.assertThat(
            mock_redfish_request,
            MockCalledOnceWith(b"DELETE", join(url, endpoint), headers),
        ) 
开发者ID:maas,项目名称:maas,代码行数:22,代码来源:test_rsd.py

示例8: test_redfish_request_continues_partial_download_error

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
def test_redfish_request_continues_partial_download_error(self):
        driver = RedfishPowerDriver()
        context = make_context()
        url = driver.get_url(context)
        uri = join(url, b"redfish/v1/Systems")
        headers = driver.make_auth_headers(**context)
        mock_agent = self.patch(redfish_module, "Agent")
        mock_agent.return_value.request = Mock()
        expected_headers = Mock()
        expected_headers.code = HTTPStatus.OK
        expected_headers.headers = "Testing Headers"
        mock_agent.return_value.request.return_value = succeed(
            expected_headers
        )
        mock_readBody = self.patch(redfish_module, "readBody")
        error = PartialDownloadError(
            response=json.dumps(SAMPLE_JSON_SYSTEMS).encode("utf-8"),
            code=HTTPStatus.OK,
        )
        mock_readBody.return_value = fail(error)
        expected_response = SAMPLE_JSON_SYSTEMS

        response, headers = yield driver.redfish_request(b"GET", uri, headers)
        self.assertEquals(expected_response, response)
        self.assertEquals(expected_headers.headers, headers) 
开发者ID:maas,项目名称:maas,代码行数:27,代码来源:test_redfish.py

示例9: test_redfish_request_raises_failures

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
def test_redfish_request_raises_failures(self):
        driver = RedfishPowerDriver()
        context = make_context()
        url = driver.get_url(context)
        uri = join(url, b"redfish/v1/Systems")
        headers = driver.make_auth_headers(**context)
        mock_agent = self.patch(redfish_module, "Agent")
        mock_agent.return_value.request = Mock()
        expected_headers = Mock()
        expected_headers.code = HTTPStatus.OK
        expected_headers.headers = "Testing Headers"
        mock_agent.return_value.request.return_value = succeed(
            expected_headers
        )
        mock_readBody = self.patch(redfish_module, "readBody")
        error = PartialDownloadError(
            response=json.dumps(SAMPLE_JSON_SYSTEMS).encode("utf-8"),
            code=HTTPStatus.NOT_FOUND,
        )
        mock_readBody.return_value = fail(error)

        with ExpectedException(PartialDownloadError):
            yield driver.redfish_request(b"GET", uri, headers)
        self.assertThat(mock_readBody, MockCalledOnceWith(expected_headers)) 
开发者ID:maas,项目名称:maas,代码行数:26,代码来源:test_redfish.py

示例10: test_getPageBrokenDownload

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

示例11: test_downloadPageLogsFileCloseError

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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.
        """
        exc = IOError(ENOSPC, "No file left on device")

        class BrokenFile:
            def write(self, bytes):
                pass

            def close(self):
                raise exc

        logObserver = EventLoggingObserver()
        filtered = FilteringLogObserver(
            logObserver,
            [LogLevelFilterPredicate(defaultLogLevel=LogLevel.critical)]
        )
        globalLogPublisher.addObserver(filtered)
        self.addCleanup(lambda: globalLogPublisher.removeObserver(filtered))

        d = client.downloadPage(self.getURL("broken"), BrokenFile())
        d = self.assertFailure(d, client.PartialDownloadError)

        def cbFailed(ignored):
            self.assertEquals(1, len(logObserver))
            event = logObserver[0]
            f = event["log_failure"]
            self.assertIsInstance(f.value, IOError)
            self.assertEquals(
                f.value.args,
                exc.args
            )
            self.assertEqual(len(self.flushLoggedErrors(IOError)), 1)

        d.addCallback(cbFailed)
        return d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:40,代码来源:test_webclient.py

示例12: test_getPageBrokenDownload

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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.assertEquals(exc.response, "abc"))
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:12,代码来源:test_webclient.py

示例13: handleResponse

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
def handleResponse(self, response):
        if self.quietLoss:
            return
        if self.failed:
            self.factory.noPage(
                failure.Failure(
                    error.Error(
                        self.status, self.message, response)))
        elif self.length != None and self.length != 0:
            self.factory.noPage(failure.Failure(
                client.PartialDownloadError(self.status, self.message, response)))
        else:
            if self.decode:
                s = StringIO()
                s.write(response)
                s.seek(-1)
                g = GzipFile(fileobj=s, mode='rb')
                try:
                    response = g.read()
                except IOError:
                    self.factory.noPage(failure.Failure(
                        client.PartialDownloadError(self.status, self.message, response)))
                    self.transport.loseConnection()
                    return
                g.close()
            self.factory.page(response)
        # server might be stupid and not close connection.
        self.transport.loseConnection() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:30,代码来源:HTTPDownloader.py

示例14: testBrokenDownload

# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import PartialDownloadError [as 别名]
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 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:8,代码来源:test_webclient.py


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