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)
| 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. |