summaryrefslogtreecommitdiffstats
path: root/Lib/locale.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-10-11 22:13:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-10-11 22:13:50 (GMT)
commitfd4722cacf4885c29d358b8de6718b51a8149fa3 (patch)
treeb6868d551a73bdc223a1263483f61072e41eb932 /Lib/locale.py
parent73abc527eb3e4b88f30b70e5404365ed24f545c9 (diff)
downloadcpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.zip
cpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.tar.gz
cpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.tar.bz2
Issue #9548: Add a minimal "_bootlocale" module that is imported by the _io module instead of the full locale module.
Diffstat (limited to 'Lib/locale.py')
-rw-r--r--Lib/locale.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index d2a885d..2e82c95 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -554,8 +554,8 @@ if sys.platform.startswith("win"):
# On Win32, this will return the ANSI code page
def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using."""
- import _locale
- return _locale._getdefaultlocale()[1]
+ import _bootlocale
+ return _bootlocale.getpreferredencoding(False)
else:
# On Unix, if CODESET is available, use that.
try:
@@ -574,27 +574,16 @@ else:
def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using,
according to the system configuration."""
+ import _bootlocale
if do_setlocale:
oldloc = setlocale(LC_CTYPE)
try:
setlocale(LC_CTYPE, "")
except Error:
pass
- result = nl_langinfo(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'
+ result = _bootlocale.getpreferredencoding(False)
+ if do_setlocale:
setlocale(LC_CTYPE, oldloc)
- else:
- result = nl_langinfo(CODESET)
- if not result and sys.platform == 'darwin':
- # See above for explanation
- result = 'UTF-8'
return result