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


Python HTTPResponse.read方法代码示例

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


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

示例1: test_reference_read

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_reference_read(self):
        fp = BytesIO(b'foo')
        r = HTTPResponse(fp, preload_content=False)

        self.assertEqual(r.read(1), b'f')
        self.assertEqual(r.read(2), b'oo')
        self.assertEqual(r.read(), b'')
        self.assertEqual(r.read(), b'')
开发者ID:Lukasa,项目名称:urllib3,代码行数:10,代码来源:test_response.py

示例2: test_reference_read

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_reference_read(self):
        fp = BytesIO(b"foo")
        r = HTTPResponse(fp, preload_content=False)

        self.assertEqual(r.read(1), b"f")
        self.assertEqual(r.read(2), b"oo")
        self.assertEqual(r.read(), b"")
        self.assertEqual(r.read(), b"")
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:10,代码来源:test_response.py

示例3: test_reference_read

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_reference_read(self):
        fp = BytesIO(b'foo')
        r = HTTPResponse(fp, preload_content=False)

        assert r.read(1) == b'f'
        assert r.read(2) == b'oo'
        assert r.read() == b''
        assert r.read() == b''
开发者ID:jonparrott,项目名称:urllib3,代码行数:10,代码来源:test_response.py

示例4: test_chunked_decoding_deflate

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_deflate(self):
        import zlib
        data = zlib.compress(b'foo')

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
                         preload_content=False)

        self.assertEqual(r.read(3), b'')
        self.assertEqual(r.read(1), b'f')
        self.assertEqual(r.read(2), b'oo')
开发者ID:Mofangbao,项目名称:urllib3,代码行数:13,代码来源:test_response.py

示例5: test_chunked_decoding_deflate

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_deflate(self):
        import zlib

        data = zlib.compress(b"foo")

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "deflate"}, preload_content=False)

        self.assertEqual(r.read(3), b"")
        self.assertEqual(r.read(1), b"f")
        self.assertEqual(r.read(2), b"oo")
开发者ID:github3py,项目名称:urllib3,代码行数:13,代码来源:test_response.py

示例6: test_chunked_decoding_deflate2

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_deflate2(self):
        import zlib
        compress = zlib.compressobj(6, zlib.DEFLATED, -zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
                         preload_content=False)

        self.assertEqual(r.read(1), b'')
        self.assertEqual(r.read(1), b'f')
        self.assertEqual(r.read(2), b'oo')
开发者ID:Mofangbao,项目名称:urllib3,代码行数:15,代码来源:test_response.py

示例7: test_chunked_decoding_gzip

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_gzip(self):
        import zlib

        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b"foo")
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "gzip"}, preload_content=False)

        self.assertEqual(r.read(11), b"")
        self.assertEqual(r.read(1), b"f")
        self.assertEqual(r.read(2), b"oo")
开发者ID:github3py,项目名称:urllib3,代码行数:15,代码来源:test_response.py

示例8: test_io_closed_consistently

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_io_closed_consistently(self):
        hlr = httplib.HTTPResponse(socket.socket())
        hlr.fp = BytesIO(b'foo')
        hlr.chunked = 0
        hlr.length = 3
        resp = HTTPResponse(hlr, preload_content=False)

        self.assertEqual(resp.closed, False)
        self.assertEqual(resp._fp.isclosed(), False)
        self.assertEqual(is_fp_closed(resp._fp), False)
        resp.read()
        self.assertEqual(resp.closed, True)
        self.assertEqual(resp._fp.isclosed(), True)
        self.assertEqual(is_fp_closed(resp._fp), True)
开发者ID:Lukasa,项目名称:urllib3,代码行数:16,代码来源:test_response.py

示例9: test_chunked_decoding_gzip

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_gzip(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'gzip'},
                         preload_content=False)

        assert r.read(11) == b''
        assert r.read(1) == b'f'
        assert r.read(2) == b'oo'
        assert r.read() == b''
        assert r.read() == b''
开发者ID:jonparrott,项目名称:urllib3,代码行数:16,代码来源:test_response.py

示例10: test_chunked_decoding_deflate2

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_deflate2(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, -zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
                         preload_content=False)

        assert r.read(1) == b''
        assert r.read(1) == b'f'
        # Once we've decoded data, we just stream to the decoder; no buffering
        assert r._decoder._data is None
        assert r.read(2) == b'oo'
        assert r.read() == b''
        assert r.read() == b''
开发者ID:jonparrott,项目名称:urllib3,代码行数:18,代码来源:test_response.py

示例11: test_chunked_decoding_deflate

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_deflate(self):
        data = zlib.compress(b'foo')

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
                         preload_content=False)

        assert r.read(3) == b''
        # Buffer in case we need to switch to the raw stream
        assert r._decoder._data is not None
        assert r.read(1) == b'f'
        # Now that we've decoded data, we just stream through the decoder
        assert r._decoder._data is None
        assert r.read(2) == b'oo'
        assert r.read() == b''
        assert r.read() == b''
开发者ID:jonparrott,项目名称:urllib3,代码行数:18,代码来源:test_response.py

示例12: test_length_after_read

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_length_after_read(self):
        headers = {"content-length": "5"}

        # Test no defined length
        fp = BytesIO(b'12345')
        resp = HTTPResponse(fp, preload_content=False)
        resp.read()
        self.assertEqual(resp.length_remaining, None)

        # Test our update from content-length
        fp = BytesIO(b'12345')
        resp = HTTPResponse(fp, headers=headers, preload_content=False)
        resp.read()
        self.assertEqual(resp.length_remaining, 0)

        # Test partial read
        fp = BytesIO(b'12345')
        resp = HTTPResponse(fp, headers=headers, preload_content=False)
        data = resp.stream(2)
        next(data)
        self.assertEqual(resp.length_remaining, 3)
开发者ID:Lukasa,项目名称:urllib3,代码行数:23,代码来源:test_response.py

示例13: test_chunked_decoding_brotli

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_chunked_decoding_brotli(self):
        data = brotli.compress(b'foobarbaz')

        fp = BytesIO(data)
        r = HTTPResponse(
            fp, headers={'content-encoding': 'br'}, preload_content=False)

        ret = b''
        for _ in range(100):
            ret += r.read(1)
            if r.closed:
                break
        assert ret == b'foobarbaz'
开发者ID:jonparrott,项目名称:urllib3,代码行数:15,代码来源:test_response.py

示例14: test_decode_gzip_swallow_garbage

# 需要导入模块: from urllib3.response import HTTPResponse [as 别名]
# 或者: from urllib3.response.HTTPResponse import read [as 别名]
    def test_decode_gzip_swallow_garbage(self):
        # When data comes from multiple calls to read(), data after
        # the first zlib error (here triggered by garbage) should be
        # ignored.
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()
        data = data * 3 + b'foo'

        fp = BytesIO(data)
        r = HTTPResponse(
            fp, headers={'content-encoding': 'gzip'}, preload_content=False)
        ret = b''
        for _ in range(100):
            ret += r.read(1)
            if r.closed:
                break

        assert ret == b'foofoofoo'
开发者ID:jonparrott,项目名称:urllib3,代码行数:21,代码来源:test_response.py


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