From b3c4d007afd83821aa699931c20276bef6465fa5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 14 Nov 2026 00:35:04 +0100 Subject: [PATCH 1/2] Log UTF-8 mode and PYTHONCOERCECLOCALE in regrtest header If the UTF-8 mode is disabled and/or if PYTHONCOERCECLOCALE environment variable is set to "0": mention it in the "== encodings" regrtest header. Also, if the locale encoding and the filesystem encoding are equal, log "locale=FS=" to have a shorter output. --- Lib/test/libregrtest/utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 41a798c71089f9e..d2f85fa6adc8b1b 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -665,8 +665,20 @@ def display_header(use_resources: dict[str, str | None], if process_cpu_count and process_cpu_count != cpu_count: cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)" print("== CPU count:", cpu_count) - print("== encodings: locale=%s FS=%s" - % (locale.getencoding(), sys.getfilesystemencoding())) + + locale_encoding = locale.getencoding() # nl_langinfo(CODESET) + fs_encoding = sys.getfilesystemencoding() # normalized name + if locale_encoding.lower() == fs_encoding.lower(): + encodings = [f'locale=FS={fs_encoding}'] + else: + encodings = [f'locale={locale_encoding}'] + encodings.append(f'FS={fs_encoding}') + if not sys.flags.utf8_mode: + encodings.append('utf8=0') + if (not sys.flags.ignore_environment + and os.environ.get('PYTHONCOERCECLOCALE') == '0'): + encodings.append('coerce=0') + print(f"== encodings: {' '.join(encodings)}") if use_resources: text = format_resources(use_resources) From b2b13894d6715e514742f66f17d70a6708cc16ac Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 14 Nov 2026 00:47:43 +0100 Subject: [PATCH 2/2] On Windows, log ANSI and OEM code pages --- Lib/test/libregrtest/utils.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index d2f85fa6adc8b1b..28e6d904fa28aab 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -666,13 +666,25 @@ def display_header(use_resources: dict[str, str | None], cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)" print("== CPU count:", cpu_count) - locale_encoding = locale.getencoding() # nl_langinfo(CODESET) - fs_encoding = sys.getfilesystemencoding() # normalized name - if locale_encoding.lower() == fs_encoding.lower(): - encodings = [f'locale=FS={fs_encoding}'] + encodings = [] + if _winapi is not None: + # Log ANSI and OEM code pages + ansi = f'cp{_winapi.GetACP()}' + oem = f'cp{_winapi.GetOEMCP()}' + if ansi == oem: + encodings.append(f'ansi=oem={ansi}') + else: + encodings.append(f'ansi={ansi}') + encodings.append(f'oem={oem}') + encodings.append(f'FS={sys.getfilesystemencoding()}') else: - encodings = [f'locale={locale_encoding}'] - encodings.append(f'FS={fs_encoding}') + locale_encoding = locale.getencoding() # nl_langinfo(CODESET) + fs_encoding = sys.getfilesystemencoding() # normalized name + if locale_encoding.lower() == fs_encoding.lower(): + encodings.append(f'locale=FS={fs_encoding}') + else: + encodings.append(f'locale={locale_encoding}') + encodings.append(f'FS={fs_encoding}') if not sys.flags.utf8_mode: encodings.append('utf8=0') if (not sys.flags.ignore_environment