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

Method read

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

Source from the content-addressed store, hash-verified

2561 return cookie
2562
2563 def read(self, size=None):
2564 self._checkReadable()
2565 if size is None:
2566 size = -1
2567 else:
2568 try:
2569 size_index = size.__index__
2570 except AttributeError:
2571 raise TypeError(f"{size!r} is not an integer")
2572 else:
2573 size = size_index()
2574 decoder = self._decoder or self._get_decoder()
2575 if size < 0:
2576 chunk = self.buffer.read()
2577 if chunk is None:
2578 raise BlockingIOError("Read returned None.")
2579 # Read everything.
2580 result = (self._get_decoded_chars() +
2581 decoder.decode(chunk, final=True))
2582 if self._snapshot is not None:
2583 self._set_decoded_chars('')
2584 self._snapshot = None
2585 return result
2586 else:
2587 # Keep reading chunks until we have size characters to return.
2588 eof = False
2589 result = self._get_decoded_chars(size)
2590 while len(result) < size and not eof:
2591 eof = not self._read_chunk()
2592 result += self._get_decoded_chars(size - len(result))
2593 return result
2594
2595 def __next__(self):
2596 self._telling = False

Callers 15

test_errorMethod · 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
test_issue1395_4Method · 0.95
test_issue1395_5Method · 0.95

Calls 8

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

Tested by 15

test_errorMethod · 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
test_issue1395_5Method · 0.76