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

Method _safe_read

Lib/http/client.py:640–665  ·  view source on GitHub ↗

Read the number of bytes requested. This function should be used when bytes "should" be present for reading. If the bytes are truly not available (due to EOF), then the IncompleteRead exception can be used to detect the problem.

(self, amt)

Source from the content-addressed store, hash-verified

638 raise IncompleteRead(bytes(b[0:total_bytes]))
639
640 def _safe_read(self, amt):
641 """Read the number of bytes requested.
642
643 This function should be used when <amt> bytes "should" be present for
644 reading. If the bytes are truly not available (due to EOF), then the
645 IncompleteRead exception can be used to detect the problem.
646 """
647 cursize = min(amt, _MIN_READ_BUF_SIZE)
648 data = self.fp.read(cursize)
649 if len(data) >= amt:
650 return data
651 if len(data) < cursize:
652 raise IncompleteRead(data, amt - len(data))
653
654 data = io.BytesIO(data)
655 data.seek(0, 2)
656 while True:
657 # This is a geometric increase in read size (never more than
658 # doubling out the current length of data per loop iteration).
659 delta = min(cursize, amt - cursize)
660 data.write(self.fp.read(delta))
661 if data.tell() >= amt:
662 return data.getvalue()
663 cursize += delta
664 if data.tell() < cursize:
665 raise IncompleteRead(data.getvalue(), amt - data.tell())
666
667 def _safe_readinto(self, b):
668 """Same as _safe_read, but for reading into a buffer."""

Callers 3

readMethod · 0.95
_get_chunk_leftMethod · 0.95
_read_chunkedMethod · 0.95

Calls 8

seekMethod · 0.95
writeMethod · 0.95
tellMethod · 0.95
getvalueMethod · 0.95
minFunction · 0.85
lenFunction · 0.85
IncompleteReadClass · 0.85
readMethod · 0.45

Tested by

no test coverage detected