MCPcopy
hub / github.com/urllib3/urllib3 / _handle_chunk

Method _handle_chunk

src/urllib3/response.py:1356–1376  ·  view source on GitHub ↗
(self, amt: int | None)

Source from the content-addressed store, hash-verified

1354 raise ProtocolError("Response ended prematurely") from None
1355
1356 def _handle_chunk(self, amt: int | None) -> bytes:
1357 returned_chunk = None
1358 if amt is None:
1359 chunk = self._fp._safe_read(self.chunk_left) # type: ignore[union-attr]
1360 returned_chunk = chunk
1361 self._fp._safe_read(2) # type: ignore[union-attr] # Toss the CRLF at the end of the chunk.
1362 self.chunk_left = None
1363 elif self.chunk_left is not None and amt < self.chunk_left:
1364 value = self._fp._safe_read(amt) # type: ignore[union-attr]
1365 self.chunk_left = self.chunk_left - amt
1366 returned_chunk = value
1367 elif amt == self.chunk_left:
1368 value = self._fp._safe_read(amt) # type: ignore[union-attr]
1369 self._fp._safe_read(2) # type: ignore[union-attr] # Toss the CRLF at the end of the chunk.
1370 self.chunk_left = None
1371 returned_chunk = value
1372 else: # amt > self.chunk_left
1373 returned_chunk = self._fp._safe_read(self.chunk_left) # type: ignore[union-attr]
1374 self._fp._safe_read(2) # type: ignore[union-attr] # Toss the CRLF at the end of the chunk.
1375 self.chunk_left = None
1376 return returned_chunk # type: ignore[no-any-return]
1377
1378 def read_chunked(
1379 self, amt: int | None = None, decode_content: bool | None = None

Callers 1

read_chunkedMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected