| 1294 | self._flush_unlocked() |
| 1295 | |
| 1296 | def _flush_unlocked(self): |
| 1297 | if self.closed: |
| 1298 | raise ValueError("flush on closed file") |
| 1299 | while self._write_buf: |
| 1300 | try: |
| 1301 | n = self.raw.write(self._write_buf) |
| 1302 | except BlockingIOError: |
| 1303 | raise RuntimeError("self.raw should implement RawIOBase: it " |
| 1304 | "should not raise BlockingIOError") |
| 1305 | if n is None: |
| 1306 | raise BlockingIOError( |
| 1307 | errno.EAGAIN, |
| 1308 | "write could not complete without blocking", 0) |
| 1309 | if n > len(self._write_buf) or n < 0: |
| 1310 | raise OSError("write() returned incorrect number of bytes") |
| 1311 | del self._write_buf[:n] |
| 1312 | |
| 1313 | def tell(self): |
| 1314 | return _BufferedIOMixin.tell(self) + len(self._write_buf) |