Commits

Victor Stinner committed 765eff6

add locale_info.py

Comments (0)

Files changed (1)

python/locale_info.py

+import locale
+import os
+import sys
+
+user_locale_encoding = locale.getpreferredencoding()
+if sys.platform == 'win32':
+    try:
+        import ctypes
+    except ImportError:
+        ansi_code_page = user_locale_encoding
+        oem_code_page = None
+        console_code_page = sys.stdin.encoding
+        console_output_code_page = sys.stdout.encoding
+    else:
+        ansi_code_page = ctypes.windll.kernel32.GetACP()
+        oem_code_page = ctypes.windll.kernel32.GetOEMCP()
+        console_code_page = ctypes.windll.kernel32.GetConsoleCP()
+        console_output_code_page = ctypes.windll.kernel32.GetConsoleOutputCP()
+
+    fs_encoding = ansi_code_page
+    fs_errors = 'strict'
+
+    print("Windows ANSI code page: %s" % ansi_code_page)
+    if oem_code_page:
+        print("Windows OEM code page: %s" % oem_code_page)
+    if console_code_page != console_output_code_page:
+        print("Windows Console input encoding: %s" % console_code_page)
+        print("Windows Console output encoding: %s" % console_output_code_page)
+    else:
+        print("Windows Console encoding: %s" % console_output_code_page)
+else:
+    fs_encoding = sys.getfilesystemencoding()
+    fs_errors = 'surrogateescape'
+    print("Locale encoding: %s" % user_locale_encoding)
+    current_locale = locale.setlocale(locale.LC_ALL, '')
+    print('setlocale(LC_ALL, "") -> %s' % (current_locale,))
+    lc_ctype = locale.getlocale(locale.LC_CTYPE)
+    print("LC_TYPE: %s" % (lc_ctype,))
+
+    for name in ('LANG', 'LC_ALL', 'LC_CTYPE'):
+        if name in os.environ:
+            value = repr(os.environ[name])
+        else:
+            value = '<unset>'
+        print("$%s: %s" % (name, value))
+
+print("Filesystem encoding: %s/%s" % (fs_encoding, fs_errors))
+