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

Method readinto

Lib/http/client.py:511–543  ·  view source on GitHub ↗

Read up to len(b) bytes into bytearray b and return the number of bytes read.

(self, b)

Source from the content-addressed store, hash-verified

509 return s
510
511 def readinto(self, b):
512 """Read up to len(b) bytes into bytearray b and return the number
513 of bytes read.
514 """
515
516 if self.fp is None:
517 return 0
518
519 if self._method == "HEAD":
520 self._close_conn()
521 return 0
522
523 if self.chunked:
524 return self._readinto_chunked(b)
525
526 if self.length is not None:
527 if len(b) > self.length:
528 # clip the read to the "end of response"
529 b = memoryview(b)[0:self.length]
530
531 # we do not use _safe_read() here because this may be a .will_close
532 # connection, and the user is reading more bytes than will be provided
533 # (for example, reading in 1k chunks)
534 n = self.fp.readinto(b)
535 if not n and b:
536 # Ideally, we would raise IncompleteRead if the content-length
537 # wasn't satisfied, but it might break compatibility.
538 self._close_conn()
539 elif self.length is not None:
540 self.length -= n
541 if not self.length:
542 self._close_conn()
543 return n
544
545 def _read_next_chunk_size(self):
546 # Read the next chunk size from the file

Calls 2

_close_connMethod · 0.95
_readinto_chunkedMethod · 0.95