gh-87587: Fix os.device_encoding() for any console on Windows (GH-155… · python/cpython@b4aea41 · GitHub
Skip to content

Commit b4aea41

Browse files
gh-87587: Fix os.device_encoding() for any console on Windows (GH-155410)
It was hard coded to map file descriptors 0, 1 and 2 to the console code page, but a console can be opened as any file descriptor, and other character devices, like NUL, are not consoles. The file handle is now queried. The UTF-8 code page is also now reported as "utf-8" instead of "cp65001".
1 parent c922aa0 commit b4aea41

3 files changed

Lines changed: 84 additions & 16 deletions

File tree

Lib/test/test_os/test_windows.py

Lines changed: 38 additions & 0 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:func:`os.device_encoding` on Windows now returns the code page of any
2+
console file descriptor, not only 0, 1 and 2, and returns ``None`` for other
3+
character devices like ``NUL``. The UTF-8 code page is now reported as
4+
``"utf-8"`` instead of ``"cp65001"``.

Python/fileutils.c

Lines changed: 42 additions & 16 deletions

0 commit comments

Comments
 (0)