本文整理汇总了Python中aiohttp.streams.StreamReader.feed_eof方法的典型用法代码示例。如果您正苦于以下问题:Python StreamReader.feed_eof方法的具体用法?Python StreamReader.feed_eof怎么用?Python StreamReader.feed_eof使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.streams.StreamReader
的用法示例。
在下文中一共展示了StreamReader.feed_eof方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_stream
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def mock_stream(data):
"""Mock a stream with data."""
protocol = mock.Mock(_reading_paused=False)
stream = StreamReader(protocol)
stream.feed_data(data)
stream.feed_eof()
return stream
示例2: test_cannot_clone_after_read
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def test_cannot_clone_after_read(loop):
payload = StreamReader(loop=loop)
payload.feed_data(b'data')
payload.feed_eof()
req = make_mocked_request('GET', '/path', payload=payload)
yield from req.read()
with pytest.raises(RuntimeError):
req.clone()
示例3: test_cannot_clone_after_read
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
async def test_cannot_clone_after_read(loop, protocol):
payload = StreamReader(protocol, loop=loop)
payload.feed_data(b'data')
payload.feed_eof()
req = make_mocked_request('GET', '/path', payload=payload)
await req.read()
with pytest.raises(RuntimeError):
req.clone()
示例4: test_reading_long_part
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
async def test_reading_long_part(self, newline) -> None:
size = 2 * stream_reader_default_limit
protocol = mock.Mock(_reading_paused=False)
stream = StreamReader(protocol)
stream.feed_data(b'0' * size + b'%s--:--' % newline)
stream.feed_eof()
obj = aiohttp.BodyPartReader(BOUNDARY, {}, stream, _newline=newline)
data = await obj.read()
assert len(data) == size
示例5: test_request_with_wrong_content_type_encoding
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
async def test_request_with_wrong_content_type_encoding(protocol) -> None:
payload = StreamReader(protocol)
payload.feed_data(b'{}')
payload.feed_eof()
headers = {'Content-Type': 'text/html; charset=test'}
req = make_mocked_request('POST', '/', payload=payload, headers=headers)
with pytest.raises(HTTPUnsupportedMediaType) as err:
await req.text()
assert err.value.status_code == 415
示例6: test_make_too_big_request_limit_None
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def test_make_too_big_request_limit_None(loop):
payload = StreamReader(loop=loop)
large_file = 1024 ** 2 * b'x'
too_large_file = large_file + b'x'
payload.feed_data(too_large_file)
payload.feed_eof()
max_size = None
req = make_mocked_request('POST', '/', payload=payload,
client_max_size=max_size)
txt = yield from req.read()
assert len(txt) == 1024**2 + 1
示例7: test_make_too_big_request
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def test_make_too_big_request(loop):
payload = StreamReader(loop=loop)
large_file = 1024 ** 2 * b'x'
too_large_file = large_file + b'x'
payload.feed_data(too_large_file)
payload.feed_eof()
req = make_mocked_request('POST', '/', payload=payload)
with pytest.raises(HTTPRequestEntityTooLarge) as err:
yield from req.read()
assert err.value.status_code == 413
示例8: test_make_too_big_request_adjust_limit
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
async def test_make_too_big_request_adjust_limit(loop, protocol):
payload = StreamReader(protocol, loop=loop)
large_file = 1024 ** 2 * b'x'
too_large_file = large_file + b'x'
payload.feed_data(too_large_file)
payload.feed_eof()
max_size = 1024**2 + 2
req = make_mocked_request('POST', '/', payload=payload,
client_max_size=max_size)
txt = await req.read()
assert len(txt) == 1024**2 + 1
示例9: test_make_too_big_request
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
async def test_make_too_big_request(protocol) -> None:
payload = StreamReader(protocol)
large_file = 1024 ** 2 * b'x'
too_large_file = large_file + b'x'
payload.feed_data(too_large_file)
payload.feed_eof()
req = make_mocked_request('POST', '/', payload=payload)
with pytest.raises(HTTPRequestEntityTooLarge) as err:
await req.read()
assert err.value.status_code == 413
示例10: test_multipart_formdata
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def test_multipart_formdata(loop):
payload = StreamReader(loop=loop)
payload.feed_data(b"""-----------------------------326931944431359\r
Content-Disposition: form-data; name="a"\r
\r
b\r
-----------------------------326931944431359\r
Content-Disposition: form-data; name="c"\r
\r
d\r
-----------------------------326931944431359--\r\n""")
content_type = "multipart/form-data; boundary="\
"---------------------------326931944431359"
payload.feed_eof()
req = make_mocked_request('POST', '/',
headers={'CONTENT-TYPE': content_type},
payload=payload)
result = yield from req.post()
assert dict(result) == {'a': 'b', 'c': 'd'}
示例11: aiohttp_payload
# 需要导入模块: from aiohttp.streams import StreamReader [as 别名]
# 或者: from aiohttp.streams.StreamReader import feed_eof [as 别名]
def aiohttp_payload(data, encoding="utf8"):
payload = RequestEncodingMixin._encode_params(data).encode(encoding)
stream = StreamReader()
stream.feed_data(payload)
stream.feed_eof()
return stream