Exemplo n.º 1
0
 async def test_read_form_while_closed(self) -> None:
     stream = Stream(b'')
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_TYPE: 'application/x-www-form-urlencoded'},
         stream)
     obj._at_eof = True
     result = await obj.form()
     assert not result
Exemplo n.º 2
0
 async def test_read_with_content_encoding_unknown(self, newline) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_ENCODING: 'snappy'},
         Stream(b'\x0e4Time to Relax!%s--:--' % newline),
         _newline=newline,
     )
     with pytest.raises(RuntimeError):
         await obj.read(decode=True)
Exemplo n.º 3
0
 async def test_read_json_compressed(self) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {
             CONTENT_ENCODING: 'deflate',
             CONTENT_TYPE: 'application/json'
         }, Stream(b'\xabV*I-.Q\xb2RP*H,.NMQ\xaa\x05\x00\r\n--:--'))
     result = await obj.json()
     assert {'test': 'passed'} == result
Exemplo n.º 4
0
 async def test_read_text_compressed(self) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {
             CONTENT_ENCODING: 'deflate',
             CONTENT_TYPE: 'text/plain'
         }, Stream(b'\x0b\xc9\xccMU(\xc9W\x08J\xcdI\xacP\x04\x00\r\n--:--'))
     result = await obj.text()
     assert 'Time to Relax!' == result
Exemplo n.º 5
0
 async def test_read_with_content_encoding_identity(self) -> None:
     thing = (b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x0b\xc9\xccMU'
              b'(\xc9W\x08J\xcdI\xacP\x04\x00$\xfb\x9eV\x0e\x00\x00\x00'
              b'\r\n')
     obj = aiohttp.BodyPartReader(BOUNDARY, {CONTENT_ENCODING: 'identity'},
                                  Stream(thing + b'--:--'))
     result = await obj.read(decode=True)
     assert thing[:-2] == result
Exemplo n.º 6
0
 async def test_read_json(self, newline) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_TYPE: 'application/json'},
         Stream(b'{"test": "passed"}%s--:--' % newline),
         _newline=newline,
     )
     result = await obj.json()
     assert {'test': 'passed'} == result
Exemplo n.º 7
0
 async def test_read_multiline(self, newline: Any) -> None:
     data = b"Hello\n,\r\nworld!%s--:--" % newline
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     result = await obj.read()
     assert b"Hello\n,\r\nworld!" == result
     result = await obj.read()
     assert b"" == result
     assert obj.at_eof()
Exemplo n.º 8
0
 async def test_read_multiline(self) -> None:
     obj = aiohttp.BodyPartReader(BOUNDARY, {},
                                  Stream(b'Hello\n,\r\nworld!\r\n--:--'))
     result = await obj.read()
     assert b'Hello\n,\r\nworld!' == result
     result = await obj.read()
     assert b'' == result
     assert obj.at_eof()
Exemplo n.º 9
0
 async def test_multi_read_chunk(self):
     stream = Stream(b'Hello,\r\n--:\r\n\r\nworld!\r\n--:--')
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, stream)
     result = await obj.read_chunk(8)
     assert b'Hello,' == result
     result = await obj.read_chunk(8)
     assert b'' == result
     assert obj.at_eof()
Exemplo n.º 10
0
 async def test_read_all_at_once(self):
     stream = Stream(b'Hello, World!\r\n--:--\r\n')
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, stream)
     result = await obj.read_chunk()
     assert b'Hello, World!' == result
     result = await obj.read_chunk()
     assert b'' == result
     assert obj.at_eof()
Exemplo n.º 11
0
 async def test_read_incomplete_body_chunked(self):
     stream = Stream(b'Hello, World!\r\n-')
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, stream)
     result = b''
     with pytest.raises(AssertionError):
         for _ in range(4):
             result += await obj.read_chunk(7)
     assert b'Hello, World!\r\n-' == result
Exemplo n.º 12
0
 async def test_next_next(self):
     obj = aiohttp.BodyPartReader(BOUNDARY, {},
                                  Stream(b'Hello, world!\r\n--:'))
     result = await obj.next()
     assert b'Hello, world!' == result
     assert obj.at_eof()
     result = await obj.next()
     assert result is None
Exemplo n.º 13
0
 async def test_read_chunk_without_content_length(self):
     obj = aiohttp.BodyPartReader(BOUNDARY, {},
                                  Stream(b'Hello, world!\r\n--:'))
     c1 = await obj.read_chunk(8)
     c2 = await obj.read_chunk(8)
     c3 = await obj.read_chunk(8)
     assert c1 + c2 == b'Hello, world!'
     assert c3 == b''
Exemplo n.º 14
0
 async def test_read_with_content_encoding_gzip(self) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_ENCODING: 'gzip'},
         Stream(b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x0b\xc9\xccMU'
                b'(\xc9W\x08J\xcdI\xacP\x04\x00$\xfb\x9eV\x0e\x00\x00\x00'
                b'\r\n--:--'))
     result = await obj.read(decode=True)
     assert b'Time to Relax!' == result
Exemplo n.º 15
0
 async def test_next_next(self, newline: Any) -> None:
     data = b"Hello, world!%s--:" % newline
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     result = await obj.next()
     assert b"Hello, world!" == result
     assert obj.at_eof()
     result = await obj.next()
     assert result is None
Exemplo n.º 16
0
 async def test_read(self, newline) -> None:
     data = b'Hello, world!%s--:' % newline
     obj = aiohttp.BodyPartReader(BOUNDARY, {},
                                  Stream(data),
                                  _newline=newline)
     result = await obj.read()
     assert b'Hello, world!' == result
     assert obj.at_eof()
Exemplo n.º 17
0
 async def test_multiread(self, newline: Any) -> None:
     data = b"Hello,%s--:%s%sworld!%s--:--" % ((newline,) * 4)
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     result = await obj.read()
     assert b"Hello," == result
     result = await obj.read()
     assert b"" == result
     assert obj.at_eof()
Exemplo n.º 18
0
 async def test_read_incomplete_body_chunked(self, newline: Any) -> None:
     data = b"Hello, World!%s--" % newline
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     result = b""
     with pytest.raises(AssertionError):
         for _ in range(4):
             result += await obj.read_chunk(7)
     assert data == result
Exemplo n.º 19
0
 async def test_read_all_at_once(self, newline: Any) -> None:
     data = b"Hello, World!%s--:--%s" % (newline, newline)
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     result = await obj.read_chunk()
     assert b"Hello, World!" == result
     result = await obj.read_chunk()
     assert b"" == result
     assert obj.at_eof()
Exemplo n.º 20
0
 async def test_read_chunk_without_content_length(self, newline: Any) -> None:
     data = b"Hello, world!%s--:" % newline
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, Stream(data), _newline=newline)
     c1 = await obj.read_chunk(8)
     c2 = await obj.read_chunk(8)
     c3 = await obj.read_chunk(8)
     assert c1 + c2 == b"Hello, world!"
     assert c3 == b""
Exemplo n.º 21
0
 async def test_multiread(self):
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {}, Stream(b'Hello,\r\n--:\r\n\r\nworld!\r\n--:--'))
     result = await obj.read()
     assert b'Hello,' == result
     result = await obj.read()
     assert b'' == result
     assert obj.at_eof()
Exemplo n.º 22
0
 async def test_read_json_while_closed(self) -> None:
     stream = Stream(b'')
     obj = aiohttp.BodyPartReader(BOUNDARY,
                                  {CONTENT_TYPE: 'application/json'},
                                  stream)
     obj._at_eof = True
     result = await obj.json()
     assert result is None
Exemplo n.º 23
0
 async def test_read_text(self, newline: Any) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY,
         {},
         Stream(b"Hello, world!%s--:--" % newline),
         _newline=newline,
     )
     result = await obj.text()
     assert "Hello, world!" == result
Exemplo n.º 24
0
 async def test_reading_long_part(self) -> None:
     size = 2 * stream_reader_default_limit
     protocol = mock.Mock(_reading_paused=False)
     stream = StreamReader(protocol)
     stream.feed_data(b'0' * size + b'\r\n--:--')
     stream.feed_eof()
     obj = aiohttp.BodyPartReader(BOUNDARY, {}, stream)
     data = await obj.read()
     assert len(data) == size
Exemplo n.º 25
0
 async def test_read_with_content_transfer_encoding_quoted_printable(self):
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_TRANSFER_ENCODING: 'quoted-printable'},
         Stream(b'=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82,'
                b' =D0=BC=D0=B8=D1=80!\r\n--:--'))
     result = await obj.read(decode=True)
     expected = (b'\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82,'
                 b' \xd0\xbc\xd0\xb8\xd1\x80!')
     assert result == expected
Exemplo n.º 26
0
 async def test_reading_long_part(self, newline) -> None:
     size = 2 * stream_reader_default_limit
     protocol = mock.Mock(_reading_paused=False)
     stream = StreamReader(protocol, loop=asyncio.get_event_loop())
     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
Exemplo n.º 27
0
 async def test_reading_long_part(self, newline: Any) -> None:
     size = 2 * 2**16
     protocol = mock.Mock(_reading_paused=False)
     stream = StreamReader(protocol, 2**16, loop=asyncio.get_event_loop())
     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
Exemplo n.º 28
0
 async def test_release_respects_content_length(self, newline) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {'CONTENT-LENGTH': 100500},
         Stream(b'.' * 100500 + b'%s--:--' % newline),
         _newline=newline,
     )
     result = await obj.release()
     assert result is None
     assert obj.at_eof()
Exemplo n.º 29
0
 async def test_read_with_content_transfer_encoding_binary(
         self, encoding) -> None:
     data = b'\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82,' \
            b' \xd0\xbc\xd0\xb8\xd1\x80!'
     obj = aiohttp.BodyPartReader(
         BOUNDARY, {CONTENT_TRANSFER_ENCODING: encoding},
         Stream(data + b'\r\n--:--'))
     result = await obj.read(decode=True)
     assert data == result
Exemplo n.º 30
0
 async def test_read_json_compressed(self, newline: Any) -> None:
     obj = aiohttp.BodyPartReader(
         BOUNDARY,
         {CONTENT_ENCODING: "deflate", CONTENT_TYPE: "application/json"},
         Stream(b"\xabV*I-.Q\xb2RP*H,.NMQ\xaa\x05\x00" b"%s--:--" % newline),
         _newline=newline,
     )
     result = await obj.json()
     assert {"test": "passed"} == result