Skip to content

Commit e4cb996

Browse files
Update compression_utils.py
1 parent 1284bd1 commit e4cb996

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

aiohttp/compression_utils.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,13 @@ def encoding_to_mode(
147147
return -ZLibBackend.MAX_WBITS if suppress_deflate_header else ZLibBackend.MAX_WBITS
148148

149149

150-
class CompressionBaseHandler(ABC):
151-
150+
class DecompressionBaseHandler(ABC):
152151
def __init__(
153152
self,
154153
executor: Executor | None = None,
155154
max_sync_chunk_size: int | None = MAX_SYNC_CHUNK_SIZE,
156155
):
157-
"""Base class for compression handlers."""
156+
"""Base class for decompression handlers."""
158157
self._executor = executor
159158
self._max_sync_chunk_size = max_sync_chunk_size
160159

@@ -174,7 +173,7 @@ async def decompress(self, data: bytes, max_length: int = 0) -> bytes:
174173
return self.decompress_sync(data, max_length)
175174

176175

177-
class ZLibCompressor(CompressionBaseHandler):
176+
class ZLibCompressor:
178177
def __init__(
179178
self,
180179
encoding: str | None = None,
@@ -185,10 +184,8 @@ def __init__(
185184
executor: Executor | None = None,
186185
max_sync_chunk_size: int | None = MAX_SYNC_CHUNK_SIZE,
187186
):
188-
super().__init__(
189-
executor=executor,
190-
max_sync_chunk_size=max_sync_chunk_size,
191-
)
187+
self._executor = executor
188+
self._max_sync_chunk_size = max_sync_chunk_size
192189
self._mode = (
193190
encoding_to_mode(encoding, suppress_deflate_header)
194191
if wbits is None
@@ -251,7 +248,7 @@ def flush(self, mode: int | None = None) -> bytes:
251248
)
252249

253250

254-
class ZLibDecompressor(CompressionBaseHandler):
251+
class ZLibDecompressor(DecompressionBaseHandler):
255252
def __init__(
256253
self,
257254
encoding: str | None = None,
@@ -279,14 +276,14 @@ def eof(self) -> bool:
279276
return self._decompressor.eof
280277

281278

282-
class BrotliDecompressor(CompressionBaseHandler):
279+
class BrotliDecompressor(DecompressionBaseHandler):
283280
# Supports both 'brotlipy' and 'Brotli' packages
284281
# since they share an import name. The top branches
285282
# are for 'brotlipy' and bottom branches for 'Brotli'
286283
def __init__(
287284
self,
288-
executor: Optional[Executor] = None,
289-
max_sync_chunk_size: Optional[int] = MAX_SYNC_CHUNK_SIZE,
285+
executor: Executor | None = None,
286+
max_sync_chunk_size: int | None = MAX_SYNC_CHUNK_SIZE,
290287
) -> None:
291288
"""Decompress data using the Brotli library."""
292289
if not HAS_BROTLI:
@@ -310,14 +307,19 @@ def flush(self) -> bytes:
310307
return b""
311308

312309

313-
class ZSTDDecompressor:
314-
def __init__(self) -> None:
310+
class ZSTDDecompressor(DecompressionBaseHandler):
311+
def __init__(
312+
self,
313+
executor: Executor | None = None,
314+
max_sync_chunk_size: int | None = MAX_SYNC_CHUNK_SIZE,
315+
) -> None:
315316
if not HAS_ZSTD:
316317
raise RuntimeError(
317318
"The zstd decompression is not available. "
318319
"Please install `backports.zstd` module"
319320
)
320321
self._obj = ZstdDecompressor()
322+
super().__init__(executor=executor, max_sync_chunk_size=max_sync_chunk_size)
321323

322324
def decompress_sync(self, data: bytes, max_length: int = 0) -> bytes:
323325
return self._obj.decompress(data, max_length)

0 commit comments

Comments
 (0)