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.
This commit is contained in:
Martin v. Löwis 2008-03-08 11:24:24 +00:00
parent ce7a112898
commit 071ef771dc
2 changed files with 12 additions and 1 deletions

View File

@ -505,7 +505,11 @@ def getpreferredencoding(do_setlocale = True):
def getpreferredencoding(do_setlocale = True): def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using, """Return the charset that the user is likely using,
by looking at environment variables.""" 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: else:
def getpreferredencoding(do_setlocale = True): def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using, """Return the charset that the user is likely using,

View File

@ -14,6 +14,13 @@ Extension Modules
- Use wchar_t functions in _locale module. - 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? What's New in Python 3.0a3?
=========================== ===========================