diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-12 00:13:50 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-12 00:13:50 +0200 |
commit | fd4722cacf4885c29d358b8de6718b51a8149fa3 (patch) | |
tree | b6868d551a73bdc223a1263483f61072e41eb932 /Lib/locale.py | |
parent | Fix expected checksum for new unicodedata (after full rebuild) (diff) | |
download | cpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.tar.gz cpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.tar.bz2 cpython-fd4722cacf4885c29d358b8de6718b51a8149fa3.zip |
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.py | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/Lib/locale.py b/Lib/locale.py index d2a885d519f..2e82c952ace 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 |