def test_parse_chunked_payload_size_error(self, stream): out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, chunked=True) with pytest.raises(http_exceptions.TransferEncodingError): p.feed_data(b'blah\r\n') assert isinstance(out.exception(), http_exceptions.TransferEncodingError)
def test_http_payload_parser_deflate(self): length = len(self._COMPRESSED) out = aiohttp.FlowControlDataQueue(self.stream) p = HttpPayloadParser(out, length=length, compression='deflate') p.feed_data(self._COMPRESSED) self.assertEqual(b'data', b''.join(d for d, _ in out._buffer)) self.assertTrue(out.is_eof())
def test_http_payload_brotli(self, stream): compressed = brotli.compress(b'brotli data') out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, length=len(compressed), compression='br') p.feed_data(compressed) assert b'brotli data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
def test_http_payload_parser_deflate(self, stream): length = len(self._COMPRESSED) out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser( out, length=length, compression='deflate') p.feed_data(self._COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
def test_http_payload_parser_length(self): out = aiohttp.FlowControlDataQueue(self.stream) p = HttpPayloadParser(out, length=2) eof, tail = p.feed_data(b'1245') self.assertTrue(eof) self.assertEqual(b'12', b''.join(d for d, _ in out._buffer)) self.assertEqual(b'45', tail)
def test_parse_eof_payload(self, stream): out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, readall=True) p.feed_data(b'data') p.feed_eof() assert out.is_eof() assert [(bytearray(b'data'), 4)] == list(out._buffer)
def test_parse_length_payload_eof(self, stream): out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, length=4) p.feed_data(b'da') with pytest.raises(http_exceptions.ContentLengthError): p.feed_eof()
def test_http_payload_parser_length(self, stream): out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, length=2) eof, tail = p.feed_data(b'1245') assert eof assert b'12' == b''.join(d for d, _ in out._buffer) assert b'45' == tail
async def test_http_payload_parser_deflate(self, stream) -> None: length = len(self._COMPRESSED) out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=length, compression='deflate') p.feed_data(self._COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
async def test_parse_chunked_payload_size_error(self, stream: Any) -> None: out = aiohttp.FlowControlDataQueue( stream, 2 ** 16, loop=asyncio.get_event_loop() ) p = HttpPayloadParser(out, chunked=True) with pytest.raises(http_exceptions.TransferEncodingError): p.feed_data(b"blah\r\n") assert isinstance(out.exception(), http_exceptions.TransferEncodingError)
def function2679(self): var942 = aiohttp.FlowControlDataQueue(self.attribute1609) var2692 = HttpPayloadParser(var942, length=2) (var3201, var2572) = var2692.feed_data(b'1245') self.assertTrue(var3201) self.assertEqual(b'12', b''.join( (d for (var64, var3572) in var942._buffer))) self.assertEqual(b'45', var2572)
def test_http_payload_brotli(self, stream): compressed = brotli.compress(b'brotli data') out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser( out, length=len(compressed), compression='br') p.feed_data(compressed) assert b'brotli data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
async def test_http_payload_brotli(self, stream: Any) -> None: compressed = brotli.compress(b"brotli data") out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=len(compressed), compression="br") p.feed_data(compressed) assert b"brotli data" == b"".join(d for d, _ in out._buffer) assert out.is_eof()
async def test_parse_length_payload_eof(self, stream) -> None: out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=4) p.feed_data(b'da') with pytest.raises(http_exceptions.ContentLengthError): p.feed_eof()
async def test_parse_eof_payload(self, stream) -> None: out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, readall=True) p.feed_data(b'data') p.feed_eof() assert out.is_eof() assert [(bytearray(b'data'), 4)] == list(out._buffer)
async def test_http_payload_parser_length(self, stream: Any) -> None: out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=2) eof, tail = p.feed_data(b"1245") assert eof assert b"12" == b"".join(d for d, _ in out._buffer) assert b"45" == tail
def function167(self): var377 = len(self.var1089) var4646 = aiohttp.FlowControlDataQueue(self.attribute1609) var4316 = HttpPayloadParser(var4646, length=var377, compression='deflate') var4316.feed_data(self.var1089) self.assertEqual( b'data', b''.join((d for (var702, var1491) in var4646._buffer))) self.assertTrue(var4646.is_eof())
def test_http_payload_parser_deflate_no_wbits(self, stream): comp = zlib.compressobj() COMPRESSED = b''.join([comp.compress(b'data'), comp.flush()]) length = len(COMPRESSED) out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser(out, length=length, compression='deflate') p.feed_data(COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
async def test_http_payload_parser_deflate_light(self, stream) -> None: # c=compressobj(wbits=9); b''.join([c.compress(b'data'), c.flush()]) COMPRESSED = b'\x18\x95KI,I\x04\x00\x04\x00\x01\x9b' length = len(COMPRESSED) out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=length, compression='deflate') p.feed_data(COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
def test_http_payload_parser_deflate_no_wbits(self, stream): comp = zlib.compressobj() COMPRESSED = b''.join([comp.compress(b'data'), comp.flush()]) length = len(COMPRESSED) out = aiohttp.FlowControlDataQueue(stream) p = HttpPayloadParser( out, length=length, compression='deflate') p.feed_data(COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
async def test_http_payload_parser_deflate(self, stream: Any) -> None: # c=compressobj(wbits=15); b''.join([c.compress(b'data'), c.flush()]) COMPRESSED = b"x\x9cKI,I\x04\x00\x04\x00\x01\x9b" length = len(COMPRESSED) out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=length, compression="deflate") p.feed_data(COMPRESSED) assert b"data" == b"".join(d for d, _ in out._buffer) assert out.is_eof()
async def test_http_payload_parser_deflate_no_hdrs(self, stream) -> None: """Tests incorrectly formed data (no zlib headers) """ # c=compressobj(wbits=-15); b''.join([c.compress(b'data'), c.flush()]) COMPRESSED = b'KI,I\x04\x00' length = len(COMPRESSED) out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=length, compression='deflate') p.feed_data(COMPRESSED) assert b'data' == b''.join(d for d, _ in out._buffer) assert out.is_eof()
async def test_http_payload_parser_length_zero(self, stream: Any) -> None: out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=0) assert p.done assert out.is_eof()
def test_parse_chunked_payload_size_error(self): out = aiohttp.FlowControlDataQueue(self.stream) p = HttpPayloadParser(out, chunked=True) self.assertRaises( http_exceptions.TransferEncodingError, p.feed_data, b'blah\r\n') self.assertIsInstance( out.exception(), http_exceptions.TransferEncodingError)
def function1441(self): var532 = aiohttp.FlowControlDataQueue(self.attribute1609) var1249 = HttpPayloadParser(var532, chunked=True) self.assertRaises(http_exceptions.TransferEncodingError, var1249.feed_data, b'blah\r\n') self.assertIsInstance(var532.exception(), http_exceptions.TransferEncodingError)
async def test_parse_no_body(self, stream) -> None: out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, method='PUT') assert out.is_eof() assert p.done
async def test_parse_chunked_payload_split_end_trailers(self, protocol) -> None: out = aiohttp.StreamReader(protocol, 2**16, loop=None) p = HttpPayloadParser(out, chunked=True) p.feed_data(b'4\r\nasdf\r\n0\r\n') p.feed_data(b'Content-MD5: 912ec803b2ce49e4a541068d495ab570\r\n') p.feed_data(b'\r\n') assert out.is_eof() assert b'asdf' == b''.join(out._buffer)
async def test_http_payload_parser_deflate_split_err(self, stream) -> None: out = aiohttp.FlowControlDataQueue(stream, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, compression='deflate', readall=True) # Feeding one wrong byte should be enough to choose exact # deflate decompressor p.feed_data(b'K', 1) p.feed_data(b'I,I\x04\x00', 5) p.feed_eof() assert b'data' == b''.join(d for d, _ in out._buffer)
async def test_parse_chunked_payload_split_end_trailers2( self, protocol: Any) -> None: out = aiohttp.StreamReader(protocol, 2**16, loop=None) p = HttpPayloadParser(out, chunked=True) p.feed_data(b"4\r\nasdf\r\n0\r\n") p.feed_data(b"Content-MD5: 912ec803b2ce49e4a541068d495ab570\r\n\r") p.feed_data(b"\n") assert out.is_eof() assert b"asdf" == b"".join(out._buffer)
async def test_http_payload_parser_deflate_split(self, stream) -> None: out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, compression="deflate", readall=True) # Feeding one correct byte should be enough to choose exact # deflate decompressor p.feed_data(b"x", 1) p.feed_data(b"\x9cKI,I\x04\x00\x04\x00\x01\x9b", 11) p.feed_eof() assert b"data" == b"".join(d for d, _ in out._buffer)
def function1736(self): var4070 = aiohttp.FlowControlDataQueue(self.attribute1609) var4592 = HttpPayloadParser(var4070, readall=True) var4592.feed_data(b'data') var4592.feed_eof() self.assertTrue(var4070.is_eof()) self.assertEqual([(bytearray(b'data'), 4)], list(var4070._buffer))
async def test_parse_chunked_payload_split_end2(self, protocol) -> None: out = aiohttp.StreamReader(protocol, 2**16, loop=None) p = HttpPayloadParser(out, chunked=True) p.feed_data(b'4\r\nasdf\r\n0\r\n\r') p.feed_data(b'\n') assert out.is_eof() assert b'asdf' == b''.join(out._buffer)
def test_parse_eof_payload(self): out = aiohttp.FlowControlDataQueue(self.stream) p = HttpPayloadParser(out, readall=True) p.feed_data(b'data') p.feed_eof() self.assertTrue(out.is_eof()) self.assertEqual([(bytearray(b'data'), 4)], list(out._buffer))
async def test_parse_chunked_payload_split_end(self, protocol) -> None: out = aiohttp.StreamReader(protocol, 2**16, loop=None) p = HttpPayloadParser(out, chunked=True) p.feed_data(b"4\r\nasdf\r\n0\r\n") p.feed_data(b"\r\n") assert out.is_eof() assert b"asdf" == b"".join(out._buffer)
def test_parse_length_payload_eof(self): out = aiohttp.FlowControlDataQueue(self.stream) p = HttpPayloadParser(out, length=4) p.feed_data(b'da') p.feed_eof()