예제 #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_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))
예제 #3
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()
예제 #4
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)
예제 #5
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))
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
0
 def test_http_payload_brotli(self):
     compressed = brotli.compress(b'brotli data')
     out = aiohttp.FlowControlDataQueue(self.stream)
     p = HttpPayloadParser(
         out, length=len(compressed), compression='br')
     p.feed_data(compressed)
     self.assertEqual(b'brotli data', b''.join(d for d, _ in out._buffer))
     self.assertTrue(out.is_eof())
예제 #10
0
 async def test_http_payload_brotli(self, stream) -> None:
     compressed = brotli.compress(b'brotli data')
     out = aiohttp.FlowControlDataQueue(stream,
                                        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()
예제 #11
0
    def test_parse_length_payload_eof(self):
        out = aiohttp.FlowControlDataQueue(self.stream)

        p = HttpPayloadParser(out, length=4)
        p.feed_data(b'da')

        with pytest.raises(http_exceptions.ContentLengthError):
            p.feed_eof()
예제 #12
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())
예제 #13
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()
예제 #14
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()
예제 #15
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)
예제 #16
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()
예제 #17
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()
예제 #18
0
    async def test_parse_chunked_payload_split_end_trailers3(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\nContent-MD5: ')
        p.feed_data(b'912ec803b2ce49e4a541068d495ab570\r\n\r\n')

        assert out.is_eof()
        assert b'asdf' == b''.join(out._buffer)
예제 #19
0
    async def test_parse_chunked_payload_split_end_trailers4(
            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" b"C")
        p.feed_data(b"ontent-MD5: 912ec803b2ce49e4a541068d495ab570\r\n\r\n")

        assert out.is_eof()
        assert b"asdf" == b"".join(out._buffer)
예제 #20
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)
예제 #21
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()
예제 #22
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)
예제 #23
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()
 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())
예제 #25
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)
예제 #26
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)
예제 #27
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()
예제 #28
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()
예제 #29
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()
예제 #30
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()
예제 #31
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
예제 #32
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
예제 #33
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)
 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)
예제 #35
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
예제 #36
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()
 def function1379(self):
     var1319 = aiohttp.FlowControlDataQueue(self.attribute1609)
     var703 = HttpPayloadParser(var1319, length=4)
     var703.feed_data(b'da')
     with pytest.raises(http_exceptions.ContentLengthError):
         var703.feed_eof()
예제 #38
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()