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

Method read

Lib/_pyio.py:2587–2617  ·  view source on GitHub ↗
(self, size=None)

Source from the content-addressed store, hash-verified

2585 return cookie
2586
2587 def read(self, size=None):
2588 self._checkReadable()
2589 if size is None:
2590 size = -1
2591 else:
2592 try:
2593 size_index = size.__index__
2594 except AttributeError:
2595 raise TypeError(f"{size!r} is not an integer")
2596 else:
2597 size = size_index()
2598 decoder = self._decoder or self._get_decoder()
2599 if size < 0:
2600 chunk = self.buffer.read()
2601 if chunk is None:
2602 raise BlockingIOError("Read returned None.")
2603 # Read everything.
2604 result = (self._get_decoded_chars() +
2605 decoder.decode(chunk, final=True))
2606 if self._snapshot is not None:
2607 self._set_decoded_chars('')
2608 self._snapshot = None
2609 return result
2610 else:
2611 # Keep reading chunks until we have size characters to return.
2612 eof = False
2613 result = self._get_decoded_chars(size)
2614 while len(result) < size and not eof:
2615 eof = not self._read_chunk()
2616 result += self._get_decoded_chars(size - len(result))
2617 return result
2618
2619 def __next__(self):
2620 self._telling = False

Callers 15

test_errorMethod · 0.95
test_fileobj_textMethod · 0.95
readtextMethod · 0.95
test_newlinesMethod · 0.95
test_newlines_inputMethod · 0.95
test_encoded_writesMethod · 0.95
test_read_one_by_oneMethod · 0.95
test_read_by_chunkMethod · 0.95
test_issue1395_1Method · 0.95
test_issue1395_2Method · 0.95
test_issue1395_3Method · 0.95

Calls 7

_get_decoderMethod · 0.95
_get_decoded_charsMethod · 0.95
_set_decoded_charsMethod · 0.95
_read_chunkMethod · 0.95
_checkReadableMethod · 0.45
readMethod · 0.45
decodeMethod · 0.45

Tested by 15

test_errorMethod · 0.76
test_fileobj_textMethod · 0.76
test_newlinesMethod · 0.76
test_newlines_inputMethod · 0.76
test_encoded_writesMethod · 0.76
test_read_one_by_oneMethod · 0.76
test_read_by_chunkMethod · 0.76
test_issue1395_1Method · 0.76
test_issue1395_2Method · 0.76
test_issue1395_3Method · 0.76
test_issue1395_4Method · 0.76