| 80 | # The size and behavior of TextIOWrapper's buffer is not part of its public |
| 81 | # API, so we handle buffering ourselves to avoid truncation. |
| 82 | def _write_chunk(self, s): |
| 83 | b = s.encode(self.encoding, self.errors) |
| 84 | if self._pending_bytes_count + len(b) > MAX_BYTES_PER_WRITE: |
| 85 | self.flush() |
| 86 | |
| 87 | self._pending_bytes.append(b) |
| 88 | self._pending_bytes_count += len(b) |
| 89 | if ( |
| 90 | self.write_through |
| 91 | or b.endswith(b"\n") |
| 92 | or self._pending_bytes_count > MAX_BYTES_PER_WRITE |
| 93 | ): |
| 94 | self.flush() |
| 95 | |
| 96 | def flush(self): |
| 97 | with self._lock: |