From: Martin v. Löwis Date: Sat, 8 Mar 2008 11:24:24 +0000 (+0000) Subject: Default to ASCII as the locale.getpreferredencoding, if the POSIX X-Git-Tag: v3.0a4~179 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=071ef771dc61b3b354a16d15ad8c6bbab130f96f;p=python Default to ASCII as the locale.getpreferredencoding, if the POSIX system doesn't support CODESET and LANG isn't set or doesn't allow deduction of an encoding. --- diff --git a/Lib/locale.py b/Lib/locale.py index ce0ca817eb..448b018a61 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -505,7 +505,11 @@ else: def getpreferredencoding(do_setlocale = True): """Return the charset that the user is likely using, by looking at environment variables.""" - return getdefaultlocale()[1] + res = getdefaultlocale()[1] + if res is None: + # LANG not set, default conservatively to ASCII + res = 'ascii' + return res else: def getpreferredencoding(do_setlocale = True): """Return the charset that the user is likely using, diff --git a/Misc/NEWS b/Misc/NEWS index 79bdef69a0..84b3d3a97e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -14,6 +14,13 @@ Extension Modules - Use wchar_t functions in _locale module. +Library +------- + +- Default to ASCII as the locale.getpreferredencoding, if the POSIX + system doesn't support CODESET and LANG isn't set or doesn't + allow deduction of an encoding. + What's New in Python 3.0a3? ===========================