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

Method readinto

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

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

Calls 3

_close_connMethod · 0.95
_readinto_chunkedMethod · 0.95
lenFunction · 0.85