| 1275 | self._flush_unlocked() |
| 1276 | |
| 1277 | def _flush_unlocked(self): |
| 1278 | if self.closed: |
| 1279 | raise ValueError("flush on closed file") |
| 1280 | while self._write_buf: |
| 1281 | try: |
| 1282 | n = self.raw.write(self._write_buf) |
| 1283 | except BlockingIOError: |
| 1284 | raise RuntimeError("self.raw should implement RawIOBase: it " |
| 1285 | "should not raise BlockingIOError") |
| 1286 | if n is None: |
| 1287 | raise BlockingIOError( |
| 1288 | errno.EAGAIN, |
| 1289 | "write could not complete without blocking", 0) |
| 1290 | if n > len(self._write_buf) or n < 0: |
| 1291 | raise OSError("write() returned incorrect number of bytes") |
| 1292 | del self._write_buf[:n] |
| 1293 | |
| 1294 | def tell(self): |
| 1295 | return _BufferedIOMixin.tell(self) + len(self._write_buf) |