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

Method read

Lib/_pyio.py:1676–1696  ·  view source on GitHub ↗

Read at most size bytes, returned as bytes. If size is less than 0, read all bytes in the file making multiple read calls. See ``FileIO.readall``. Attempts to make only one system call, retrying only per PEP 475 (EINTR). This means less data may be returned than

(self, size=None)

Source from the content-addressed store, hash-verified

1674 raise UnsupportedOperation('File not open for writing')
1675
1676 def read(self, size=None):
1677 """Read at most size bytes, returned as bytes.
1678
1679 If size is less than 0, read all bytes in the file making
1680 multiple read calls. See ``FileIO.readall``.
1681
1682 Attempts to make only one system call, retrying only per
1683 PEP 475 (EINTR). This means less data may be returned than
1684 requested.
1685
1686 In non-blocking mode, returns None if no data is available.
1687 Return an empty bytes object at EOF.
1688 """
1689 self._checkClosed()
1690 self._checkReadable()
1691 if size is None or size < 0:
1692 return self.readall()
1693 try:
1694 return os.read(self._fd, size)
1695 except BlockingIOError:
1696 return None
1697
1698 def readall(self):
1699 """Read all data from the file, returned as bytes.

Callers 13

testBytesOpenMethod · 0.95
testUtf8BytesOpenMethod · 0.95
bug801631Method · 0.95
testAppendMethod · 0.95
readlineMethod · 0.45
_read_unlockedMethod · 0.45
_peek_unlockedMethod · 0.45
readMethod · 0.45
readMethod · 0.45
_read_chunkMethod · 0.45
seekMethod · 0.45

Calls 3

_checkReadableMethod · 0.95
readallMethod · 0.95
_checkClosedMethod · 0.45

Tested by 5

testBytesOpenMethod · 0.76
testUtf8BytesOpenMethod · 0.76
bug801631Method · 0.76
testAppendMethod · 0.76