예제 #1
0
 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)
예제 #2
0
 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())
예제 #3
0
 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()
예제 #4
0
 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)
예제 #5
0
 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()
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
    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()
예제 #9
0
    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
예제 #10
0
 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()
예제 #11
0
 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)
예제 #13
0
 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()
예제 #14
0
    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
예제 #15
0
 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()
예제 #16
0
    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()
예제 #17
0
    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)
예제 #18
0
    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())
예제 #20
0
    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()
예제 #21
0
    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()
예제 #22
0
    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()
예제 #23
0
    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()
예제 #24
0
    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()
예제 #25
0
 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()
예제 #26
0
 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)
예제 #28
0
    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
예제 #29
0
    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)
예제 #30
0
 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)
예제 #31
0
    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)
예제 #32
0
 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))
예제 #34
0
    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)
예제 #35
0
    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()
예제 #36
0
    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)
예제 #37
0
    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))
예제 #38
0
    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)
예제 #39
0
    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()
예제 #40
0
    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()