MCPcopy
hub / github.com/urllib3/urllib3 / decompress

Method decompress

src/urllib3/response.py:325–349  ·  view source on GitHub ↗
(self, data: bytes, max_length: int = -1)

Source from the content-addressed store, hash-verified

323 return self._decoders[0].flush()
324
325 def decompress(self, data: bytes, max_length: int = -1) -> bytes:
326 if max_length <= 0:
327 for d in reversed(self._decoders):
328 data = d.decompress(data)
329 return data
330
331 ret = bytearray()
332 # Every while loop iteration goes through all decoders once.
333 # It exits when enough data is read or no more data can be read.
334 # It is possible that the while loop iteration does not produce
335 # any data because we retrieve up to `max_length` from every
336 # decoder, and the amount of bytes may be insufficient for the
337 # next decoder to produce enough/any output.
338 while True:
339 any_data = False
340 for d in reversed(self._decoders):
341 data = d.decompress(data, max_length=max_length - len(ret))
342 if data:
343 any_data = True
344 # We should not break when no data is returned because
345 # next decoders may produce data even with empty input.
346 ret += data
347 if not any_data or len(ret) >= max_length:
348 return bytes(ret)
349 data = b""
350
351 @property
352 def has_unconsumed_tail(self) -> bool:

Callers

nothing calls this directly

Calls 1

decompressMethod · 0.45

Tested by

no test coverage detected