當前位置: 首頁>>代碼示例>>Python>>正文


Python streams.StreamReader類代碼示例

本文整理匯總了Python中aiohttp.streams.StreamReader的典型用法代碼示例。如果您正苦於以下問題:Python StreamReader類的具體用法?Python StreamReader怎麽用?Python StreamReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StreamReader類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mock_stream

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
開發者ID:keatontaylor,項目名稱:home-assistant,代碼行數:7,代碼來源:aiohttp.py

示例2: test_cannot_clone_after_read

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()
開發者ID:gleb-chipiga,項目名稱:aiohttp,代碼行數:8,代碼來源:test_web_request.py

示例3: test_cannot_clone_after_read

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()
開發者ID:youpengly,項目名稱:aiohttp,代碼行數:8,代碼來源:test_web_request.py

示例4: test_reading_long_part

 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
開發者ID:samuelcolvin,項目名稱:aiohttp,代碼行數:9,代碼來源:test_multipart.py

示例5: test_request_with_wrong_content_type_encoding

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
開發者ID:KeepSafe,項目名稱:aiohttp,代碼行數:10,代碼來源:test_web_request.py

示例6: test_make_too_big_request_limit_None

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
開發者ID:gleb-chipiga,項目名稱:aiohttp,代碼行數:11,代碼來源:test_web_request.py

示例7: test_make_too_big_request

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
開發者ID:gleb-chipiga,項目名稱:aiohttp,代碼行數:11,代碼來源:test_web_request.py

示例8: test_make_too_big_request_adjust_limit

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
開發者ID:youpengly,項目名稱:aiohttp,代碼行數:11,代碼來源:test_web_request.py

示例9: test_make_too_big_request

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
開發者ID:KeepSafe,項目名稱:aiohttp,代碼行數:11,代碼來源:test_web_request.py

示例10: test_multipart_formdata

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'}
開發者ID:gleb-chipiga,項目名稱:aiohttp,代碼行數:19,代碼來源:test_web_request.py

示例11: aiohttp_payload

def aiohttp_payload(data, encoding="utf8"):
    payload = RequestEncodingMixin._encode_params(data).encode(encoding)
    stream = StreamReader()
    stream.feed_data(payload)
    stream.feed_eof()
    return stream
開發者ID:Tygs,項目名稱:tygs,代碼行數:6,代碼來源:test_utils.py


注:本文中的aiohttp.streams.StreamReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。