Skip to content

Commit eb76fbb

Browse files
committed
Handle "cp65001" pseudo-encoding correctly on Python 2.7.
1 parent 2541b90 commit eb76fbb

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/debugpy/launcher/output.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ def __init__(self, whose, category, fd, stream):
3636
self._stream = None
3737
else:
3838
self._stream = stream if sys.version_info < (3,) else stream.buffer
39-
self._encode = codecs.getencoder(
40-
"utf-8" if stream.encoding is None else stream.encoding
41-
)
39+
encoding = stream.encoding
40+
if encoding is None or encoding == "cp65001":
41+
encoding = "utf-8"
42+
try:
43+
self._encode = codecs.getencoder(encoding)
44+
except Exception:
45+
log.swallow_exception(
46+
"Unsupported {0} encoding {1!r}; falling back to UTF-8.",
47+
category,
48+
encoding,
49+
level="warning",
50+
)
51+
self._encode = codecs.getencoder("utf-8")
4252

4353
self._worker_thread = threading.Thread(target=self._worker, name=category)
4454
self._worker_thread.start()

0 commit comments

Comments
 (0)