summaryrefslogtreecommitdiffstats
path: root/Lib/_bootlocale.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-10-31 00:32:11 (GMT)
committerGitHub <noreply@github.com>2020-10-31 00:32:11 (GMT)
commitb62bdf71ea0cd52041d49691d8ae3dc645bd48e1 (patch)
tree376fe1864673d8de21c8621629765cd1a28cdb1b /Lib/_bootlocale.py
parent710e82630775774dceba5e8f24b1b10e6dfaf9b7 (diff)
downloadcpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.zip
cpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.tar.gz
cpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.tar.bz2
bpo-42208: Add _locale._get_locale_encoding() (GH-23052)
* Add a new _locale._get_locale_encoding() function to get the current locale encoding. * Modify locale.getpreferredencoding() to use it. * Remove the _bootlocale module.
Diffstat (limited to 'Lib/_bootlocale.py')
-rw-r--r--Lib/_bootlocale.py46
1 files changed, 0 insertions, 46 deletions
diff --git a/Lib/_bootlocale.py b/Lib/_bootlocale.py
deleted file mode 100644
index 3273a3b..0000000
--- a/Lib/_bootlocale.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""A minimal subset of the locale module used at interpreter startup
-(imported by the _io module), in order to reduce startup time.
-
-Don't import directly from third-party code; use the `locale` module instead!
-"""
-
-import sys
-import _locale
-
-if sys.platform.startswith("win"):
- def getpreferredencoding(do_setlocale=True):
- if sys.flags.utf8_mode:
- return 'UTF-8'
- return _locale._getdefaultlocale()[1]
-else:
- try:
- _locale.CODESET
- except AttributeError:
- if hasattr(sys, 'getandroidapilevel'):
- # On Android langinfo.h and CODESET are missing, and UTF-8 is
- # always used in mbstowcs() and wcstombs().
- def getpreferredencoding(do_setlocale=True):
- return 'UTF-8'
- else:
- def getpreferredencoding(do_setlocale=True):
- if sys.flags.utf8_mode:
- return 'UTF-8'
- # This path for legacy systems needs the more complex
- # getdefaultlocale() function, import the full locale module.
- import locale
- return locale.getpreferredencoding(do_setlocale)
- else:
- def getpreferredencoding(do_setlocale=True):
- assert not do_setlocale
- if sys.flags.utf8_mode:
- return 'UTF-8'
- result = _locale.nl_langinfo(_locale.CODESET)
- if not result and sys.platform == 'darwin':
- # nl_langinfo can return an empty string
- # when the setting has an invalid value.
- # Default to UTF-8 in that case because
- # UTF-8 is the default charset on OSX and
- # returning nothing will crash the
- # interpreter.
- result = 'UTF-8'
- return result