本文整理汇总了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'')
示例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"")
示例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''
示例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')
示例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")
示例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')
示例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")
示例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)
示例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''
示例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''
示例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''
示例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)
示例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'
示例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'