]> granicus.if.org Git - python/commitdiff
Default to ASCII as the locale.getpreferredencoding, if the POSIX
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 8 Mar 2008 11:24:24 +0000 (11:24 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 8 Mar 2008 11:24:24 +0000 (11:24 +0000)
system doesn't support CODESET and LANG isn't set or doesn't
allow deduction of an encoding.

Lib/locale.py
Misc/NEWS

index ce0ca817eb138d5fdb43a22fffb2190581268dbf..448b018a618d53e1cfb7b70c726cc5d6c1ae6f83 100644 (file)
@@ -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,
index 79bdef69a0be096ec576433ee2ff546cd8eae97a..84b3d3a97ed82f27ed6afb3e671ba570c55752c4 100644 (file)
--- 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?
 ===========================