From eb76fbb2e3abc31aacbbf985b55909a220927ddf Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Wed, 25 Mar 2020 19:14:25 -0700 Subject: [PATCH] Handle "cp65001" pseudo-encoding correctly on Python 2.7. --- src/debugpy/launcher/output.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/debugpy/launcher/output.py b/src/debugpy/launcher/output.py index f0733823..07e3d5e6 100644 --- a/src/debugpy/launcher/output.py +++ b/src/debugpy/launcher/output.py @@ -36,9 +36,19 @@ class CaptureOutput(object): self._stream = None else: self._stream = stream if sys.version_info < (3,) else stream.buffer - self._encode = codecs.getencoder( - "utf-8" if stream.encoding is None else stream.encoding - ) + encoding = stream.encoding + if encoding is None or encoding == "cp65001": + encoding = "utf-8" + try: + self._encode = codecs.getencoder(encoding) + except Exception: + log.swallow_exception( + "Unsupported {0} encoding {1!r}; falling back to UTF-8.", + category, + encoding, + level="warning", + ) + self._encode = codecs.getencoder("utf-8") self._worker_thread = threading.Thread(target=self._worker, name=category) self._worker_thread.start()