MCPcopy Index your code
hub / github.com/RustPython/RustPython / read

Method read

Lib/http/client.py:468–506  ·  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

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

Callers 15

test_status_linesMethod · 0.95
test_partial_readsMethod · 0.95
test_mixed_readsMethod · 0.95
test_read_headMethod · 0.95
test_chunkedMethod · 0.95
test_chunked_headMethod · 0.95
test_incomplete_readMethod · 0.95
test_early_eofMethod · 0.95

Calls 4

_close_connMethod · 0.95
_read_chunkedMethod · 0.95
_safe_readMethod · 0.95
lenFunction · 0.85

Tested by 15

test_status_linesMethod · 0.76
test_partial_readsMethod · 0.76
test_mixed_readsMethod · 0.76
test_read_headMethod · 0.76
test_chunkedMethod · 0.76
test_chunked_headMethod · 0.76
test_incomplete_readMethod · 0.76
test_early_eofMethod · 0.76