| 164 | self.write_raw(msg, flush=flush) |
| 165 | |
| 166 | def write_raw(self, msg: str, *, flush: bool = False) -> None: |
| 167 | try: |
| 168 | self._file.write(msg) |
| 169 | except UnicodeEncodeError: |
| 170 | # Some environments don't support printing general Unicode |
| 171 | # strings, due to misconfiguration or otherwise; in that case, |
| 172 | # print the string escaped to ASCII. |
| 173 | # When the Unicode situation improves we should consider |
| 174 | # letting the error propagate instead of masking it (see #7475 |
| 175 | # for one brief attempt). |
| 176 | msg = msg.encode("unicode-escape").decode("ascii") |
| 177 | self._file.write(msg) |
| 178 | |
| 179 | if flush: |
| 180 | self.flush() |
| 181 | |
| 182 | def line(self, s: str = "", **markup: bool) -> None: |
| 183 | self.write(s, **markup) |