Skip to content

Commit 21364c9

Browse files
committed
Address review feedback on GzipDecompressor
- Remove unnecessary getattr() guard on unused_data since it's a documented member of zlib.Decompress - Simplify decompress loop by always passing remaining to decompressobj.decompress() (0 means unlimited) - Fix remaining calculation to not clamp negative values to 0, which would incorrectly mean "no limit"
1 parent b4baad1 commit 21364c9

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

tornado/util.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,16 @@ def decompress(self, value: bytes, max_length: int = 0) -> bytes:
9191
remaining = max_length
9292

9393
while True:
94-
if remaining:
95-
chunk = self.decompressobj.decompress(data, remaining)
96-
else:
97-
chunk = self.decompressobj.decompress(data)
98-
94+
chunk = self.decompressobj.decompress(data, remaining)
9995
out.extend(chunk)
10096

101-
if remaining:
102-
remaining = max(0, max_length - len(out))
103-
if remaining == 0:
97+
if max_length:
98+
remaining = max_length - len(out)
99+
if remaining <= 0:
104100
break
105101

106102
# Handle concatenated gzip members
107-
unused = getattr(self.decompressobj, "unused_data", b"")
103+
unused = self.decompressobj.unused_data
108104
if unused:
109105
data = unused
110106
self.decompressobj = zlib.decompressobj(16 + zlib.MAX_WBITS)

0 commit comments

Comments
 (0)