Write bytes to a stream. :param stream: the stream being written to :param to_write: the bytes being written.
(stream: StdSim | TextIO, to_write: bytes | str)
| 604 | |
| 605 | @staticmethod |
| 606 | def _write_bytes(stream: StdSim | TextIO, to_write: bytes | str) -> None: |
| 607 | """Write bytes to a stream. |
| 608 | |
| 609 | :param stream: the stream being written to |
| 610 | :param to_write: the bytes being written. |
| 611 | """ |
| 612 | if isinstance(to_write, str): |
| 613 | to_write = to_write.encode() |
| 614 | |
| 615 | # BrokenPipeError can occur if output is being piped to a process that closed |
| 616 | with contextlib.suppress(BrokenPipeError): |
| 617 | stream.buffer.write(to_write) |
| 618 | |
| 619 | |
| 620 | class ContextFlag: |
no test coverage detected