diff options
author | Victor Stinner <vstinner@python.org> | 2022-02-22 21:04:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-22 21:04:07 (GMT) |
commit | ccbe8045faf6e63d36229ea4e1b9298572cda126 (patch) | |
tree | 398e7157040957ec220da5f8c7a00fd7fcad3c1b /Lib/encodings | |
parent | 8fb94893e4a870ed3533e80c4bc2f1ebf1cfa9e7 (diff) | |
download | cpython-ccbe8045faf6e63d36229ea4e1b9298572cda126.zip cpython-ccbe8045faf6e63d36229ea4e1b9298572cda126.tar.gz cpython-ccbe8045faf6e63d36229ea4e1b9298572cda126.tar.bz2 |
bpo-46659: Fix the MBCS codec alias on Windows (GH-31218)
Diffstat (limited to 'Lib/encodings')
-rw-r--r-- | Lib/encodings/__init__.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index dff22a4..f9075b8 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -152,7 +152,14 @@ def search_function(encoding): # Return the registry entry return entry +# Register the search_function in the Python codec registry +codecs.register(search_function) + if sys.platform == 'win32': + # bpo-671666, bpo-46668: If Python does not implement a codec for current + # Windows ANSI code page, use the "mbcs" codec instead: + # WideCharToMultiByte() and MultiByteToWideChar() functions with CP_ACP. + # Python does not support custom code pages. def _alias_mbcs(encoding): try: import _winapi @@ -164,8 +171,4 @@ if sys.platform == 'win32': # Imports may fail while we are shutting down pass - # It must be registered before search_function() codecs.register(_alias_mbcs) - -# Register the search_function in the Python codec registry -codecs.register(search_function) |