Skip to content

Commit

Permalink
Remove unused readall from Python parser (#8096)
Browse files Browse the repository at this point in the history
(cherry picked from commit 175954c)
  • Loading branch information
Dreamsorcerer committed Apr 21, 2024
1 parent 9bd65fa commit 64840f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 45 deletions.
20 changes: 1 addition & 19 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
TransferEncodingError,
)
from .http_writer import HttpVersion, HttpVersion10
from .log import internal_logger
from .streams import EMPTY_PAYLOAD, StreamReader
from .typedefs import RawHeaders

Expand Down Expand Up @@ -249,7 +248,6 @@ def __init__(
timer: Optional[BaseTimerContext] = None,
code: Optional[int] = None,
method: Optional[str] = None,
readall: bool = False,
payload_exception: Optional[Type[BaseException]] = None,
response_with_body: bool = True,
read_until_eof: bool = False,
Expand All @@ -263,7 +261,6 @@ def __init__(
self.timer = timer
self.code = code
self.method = method
self.readall = readall
self.payload_exception = payload_exception
self.response_with_body = response_with_body
self.read_until_eof = read_until_eof
Expand Down Expand Up @@ -393,7 +390,6 @@ def get_content_length() -> Optional[int]:
method=method,
compression=msg.compression,
code=self.code,
readall=self.readall,
response_with_body=self.response_with_body,
auto_decompress=self._auto_decompress,
lax=self.lax,
Expand All @@ -413,7 +409,6 @@ def get_content_length() -> Optional[int]:
payload,
method=msg.method,
compression=msg.compression,
readall=True,
auto_decompress=self._auto_decompress,
lax=self.lax,
)
Expand All @@ -431,7 +426,6 @@ def get_content_length() -> Optional[int]:
method=method,
compression=msg.compression,
code=self.code,
readall=True,
response_with_body=self.response_with_body,
auto_decompress=self._auto_decompress,
lax=self.lax,
Expand Down Expand Up @@ -751,13 +745,12 @@ def __init__(
compression: Optional[str] = None,
code: Optional[int] = None,
method: Optional[str] = None,
readall: bool = False,
response_with_body: bool = True,
auto_decompress: bool = True,
lax: bool = False,
) -> None:
self._length = 0
self._type = ParseState.PARSE_NONE
self._type = ParseState.PARSE_UNTIL_EOF
self._chunk = ChunkState.PARSE_CHUNKED_SIZE
self._chunk_size = 0
self._chunk_tail = b""
Expand All @@ -779,7 +772,6 @@ def __init__(
self._type = ParseState.PARSE_NONE
real_payload.feed_eof()
self.done = True

elif chunked:
self._type = ParseState.PARSE_CHUNKED
elif length is not None:
Expand All @@ -788,16 +780,6 @@ def __init__(
if self._length == 0:
real_payload.feed_eof()
self.done = True
else:
if readall and code != 204:
self._type = ParseState.PARSE_UNTIL_EOF
elif method in ("PUT", "POST"):
internal_logger.warning( # pragma: no cover
"Content-Length or Transfer-Encoding header is required"
)
self._type = ParseState.PARSE_NONE
real_payload.feed_eof()
self.done = True

self.payload = real_payload

Expand Down
35 changes: 9 additions & 26 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,8 @@ def test_parse_chunked_payload_chunk_extension(parser) -> None:
assert payload.is_eof()


def _test_parse_no_length_or_te_on_post(loop, protocol, request_cls):
parser = request_cls(protocol, loop, readall=True)
def test_parse_no_length_or_te_on_post(loop: Any, protocol: Any, request_cls: Any):
parser = request_cls(protocol, loop, limit=2**16)
text = b"POST /test HTTP/1.1\r\n\r\n"
msg, payload = parser.feed_data(text)[0][0]

Expand Down Expand Up @@ -1475,29 +1475,16 @@ def test_parse_bad_method_for_c_parser_raises(loop, protocol):

class TestParsePayload:
async def test_parse_eof_payload(self, stream) -> None:
out = aiohttp.FlowControlDataQueue(
stream, 2**16, loop=asyncio.get_event_loop()
)
p = HttpPayloadParser(out, readall=True)
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out)
p.feed_data(b"data")
p.feed_eof()

assert out.is_eof()
assert [(bytearray(b"data"), 4)] == list(out._buffer)

async def test_parse_no_body(self, stream) -> None:
out = aiohttp.FlowControlDataQueue(
stream, 2**16, loop=asyncio.get_event_loop()
)
p = HttpPayloadParser(out, method="PUT")

assert out.is_eof()
assert p.done

async def test_parse_length_payload_eof(self, stream) -> None:
out = aiohttp.FlowControlDataQueue(
stream, 2**16, loop=asyncio.get_event_loop()
)
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())

p = HttpPayloadParser(out, length=4)
p.feed_data(b"da")
Expand Down Expand Up @@ -1622,10 +1609,8 @@ async def test_http_payload_parser_deflate_light(self, stream) -> None:
assert out.is_eof()

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)
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out, compression="deflate")
# Feeding one correct byte should be enough to choose exact
# deflate decompressor
p.feed_data(b"x", 1)
Expand All @@ -1634,10 +1619,8 @@ async def test_http_payload_parser_deflate_split(self, stream) -> None:
assert b"data" == b"".join(d for d, _ in out._buffer)

async def test_http_payload_parser_deflate_split_err(self, stream) -> None:
out = aiohttp.FlowControlDataQueue(
stream, 2**16, loop=asyncio.get_event_loop()
)
p = HttpPayloadParser(out, compression="deflate", readall=True)
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out, compression="deflate")
# Feeding one wrong byte should be enough to choose exact
# deflate decompressor
p.feed_data(b"K", 1)
Expand Down

0 comments on commit 64840f4

Please sign in to comment.