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)
| 1653 | raise UnsupportedOperation('File not open for writing') |
| 1654 | |
| 1655 | def read(self, size=None): |
| 1656 | """Read at most size bytes, returned as bytes. |
| 1657 | |
| 1658 | If size is less than 0, read all bytes in the file making |
| 1659 | multiple read calls. See ``FileIO.readall``. |
| 1660 | |
| 1661 | Attempts to make only one system call, retrying only per |
| 1662 | PEP 475 (EINTR). This means less data may be returned than |
| 1663 | requested. |
| 1664 | |
| 1665 | In non-blocking mode, returns None if no data is available. |
| 1666 | Return an empty bytes object at EOF. |
| 1667 | """ |
| 1668 | self._checkClosed() |
| 1669 | self._checkReadable() |
| 1670 | if size is None or size < 0: |
| 1671 | return self.readall() |
| 1672 | try: |
| 1673 | return os.read(self._fd, size) |
| 1674 | except BlockingIOError: |
| 1675 | return None |
| 1676 | |
| 1677 | def readall(self): |
| 1678 | """Read all data from the file, returned as bytes. |