MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / read

Method read

tools/python-3.11.9-amd64/Lib/http/client.py:457–495  ·  view source on GitHub ↗

Read and return the response body, or up to the next amt bytes.

(self, amt=None)

Source from the content-addressed store, hash-verified

455 return self.fp is None
456
457 def read(self, amt=None):
458 """Read and return the response body, or up to the next amt bytes."""
459 if self.fp is None:
460 return b""
461
462 if self._method == "HEAD":
463 self._close_conn()
464 return b""
465
466 if self.chunked:
467 return self._read_chunked(amt)
468
469 if amt is not None:
470 if self.length is not None and amt > self.length:
471 # clip the read to the "end of response"
472 amt = self.length
473 s = self.fp.read(amt)
474 if not s and amt:
475 # Ideally, we would raise IncompleteRead if the content-length
476 # wasn't satisfied, but it might break compatibility.
477 self._close_conn()
478 elif self.length is not None:
479 self.length -= len(s)
480 if not self.length:
481 self._close_conn()
482 return s
483 else:
484 # Amount is not given (unbounded read) so we must check self.length
485 if self.length is None:
486 s = self.fp.read()
487 else:
488 try:
489 s = self._safe_read(self.length)
490 except IncompleteRead:
491 self._close_conn()
492 raise
493 self.length = 0
494 self._close_conn() # we read everything
495 return s
496
497 def readinto(self, b):
498 """Read up to len(b) bytes into bytearray b and return the number

Callers 4

_safe_readMethod · 0.45
sendMethod · 0.45
_read_readableMethod · 0.45
run_cgiMethod · 0.45

Calls 3

_close_connMethod · 0.95
_read_chunkedMethod · 0.95
_safe_readMethod · 0.95

Tested by

no test coverage detected