MCPcopy Index your code
hub / github.com/python/cpython / read

Method read

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

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

_close_connMethod · 0.95
_read_chunkedMethod · 0.95
_safe_readMethod · 0.95

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