Skip to content

Commit

Permalink
cleanup, adjust comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 6, 2024
1 parent 0201636 commit 6b931f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions aiohttp/http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@


MIN_PAYLOAD_FOR_WRITELINES = 2048
UNSAFE_WRITELINES = (3, 13, 0) <= sys.version_info < (3, 13, 2) or sys.version_info < (
3,
12,
9,
)
# writelines is not safe for use until 3.12.9 and 3.13.2
IS_PY313_BEFORE_313_2 = (3, 13, 0) <= sys.version_info < (3, 13, 2)
IS_BEFORE_312_9 = sys.version_info < (3, 12, 9)
SKIP_WRITELINES = IS_PY313_BEFORE_313_2 or IS_BEFORE_312_9
# writelines is not safe for use
# on Python 3.12+ until 3.12.9
# on Python 3.13+ until 3.13.2
# and on older versions it not any faster than write
# CVE-2024-12254: https://github.com/python/cpython/pull/127656


Expand Down Expand Up @@ -101,7 +102,7 @@ def _writelines(self, chunks: Iterable[bytes]) -> None:
transport = self._protocol.transport
if transport is None or transport.is_closing():
raise ClientConnectionResetError("Cannot write to closing transport")
if UNSAFE_WRITELINES or size < MIN_PAYLOAD_FOR_WRITELINES:
if SKIP_WRITELINES or size < MIN_PAYLOAD_FOR_WRITELINES:
transport.write(b"".join(chunks))
else:
transport.writelines(chunks)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@pytest.fixture
def enable_writelines() -> Generator[None, None, None]:
with mock.patch("aiohttp.http_writer.UNSAFE_WRITELINES", False):
with mock.patch("aiohttp.http_writer.SKIP_WRITELINES", False):
yield


Expand Down

0 comments on commit 6b931f8

Please sign in to comment.