Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 17, 2024
1 parent 98c83e4 commit 8c787fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion aiohttp/_websocket/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def ws_ext_parse(


def ws_ext_gen(
compress: int = zlib.MAX_WBITS, isserver: bool = False, server_notakeover: bool = False
compress: int = zlib.MAX_WBITS,
isserver: bool = False,
server_notakeover: bool = False,
) -> str:
# client_notakeover=False not used for server
# compress wbit 8 does not support in zlib
Expand Down
8 changes: 5 additions & 3 deletions aiohttp/_websocket/reader_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ def _read_from_buffer(self) -> WSMessage:

class WebSocketReader:
def __init__(
self, queue: WebSocketDataQueue, max_msg_size: int, compress: bool | Literal["gzip"] = True
self,
queue: WebSocketDataQueue,
max_msg_size: int,
compress: bool | Literal["gzip"] = True,
) -> None:
self.queue = queue
self._max_msg_size = max_msg_size
Expand Down Expand Up @@ -243,8 +246,7 @@ def _feed_data(self, data: bytes) -> None:
if not self._decompressobj:
encoding = "gzip" if self._compress == "gzip" else None
self._decompressobj = ZLibDecompressor(
encoding=encoding,
suppress_deflate_header=True
encoding=encoding, suppress_deflate_header=True
)
payload_merged = self._decompressobj.decompress_sync(
assembled_payload + WS_DEFLATE_TRAILING, self._max_msg_size
Expand Down
13 changes: 9 additions & 4 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,9 @@ async def _ws_connect(
compress_hdrs = resp.headers.get(hdrs.SEC_WEBSOCKET_EXTENSIONS)
if compress_hdrs:
try:
compress, notakeover = ws_ext_parse(compress_hdrs, detect_gzip=True)
compress, notakeover = ws_ext_parse(
compress_hdrs, detect_gzip=True
)
except WSHandshakeError as exc:
raise WSServerHandshakeError(
resp.request_info,
Expand Down Expand Up @@ -1036,9 +1038,12 @@ async def _ws_connect(
transport = conn.transport
assert transport is not None
reader = WebSocketDataQueue(conn_proto, 2**16, loop=self._loop)
conn_proto.set_parser(WebSocketReader(
reader, max_msg_size, compress=compress <= zlib.MAX_WBITS or "gzip"
), reader)
conn_proto.set_parser(
WebSocketReader(
reader, max_msg_size, compress=compress <= zlib.MAX_WBITS or "gzip"
),
reader,
)
writer = WebSocketWriter(
conn_proto,
transport,
Expand Down

0 comments on commit 8c787fb

Please sign in to comment.