[Python-checkins] r72375 - python/trunk/Lib/locale.py

jeroen.ruigrok python-checkins at python.org
Wed May 6 07:25:43 CEST 2009


Author: jeroen.ruigrok
Date: Wed May  6 07:25:42 2009
New Revision: 72375

Log:
Wrap getpreferredencoding()'s use of setlocale in a try/except to prevent
us from raising an exception when the locale is invalid.

Issue #1443504


Modified:
   python/trunk/Lib/locale.py

Modified: python/trunk/Lib/locale.py
==============================================================================
--- python/trunk/Lib/locale.py	(original)
+++ python/trunk/Lib/locale.py	Wed May  6 07:25:42 2009
@@ -553,7 +553,10 @@
             according to the system configuration."""
             if do_setlocale:
                 oldloc = setlocale(LC_CTYPE)
-                setlocale(LC_CTYPE, "")
+                try:
+                    setlocale(LC_CTYPE, "")
+                except:
+                    pass
                 result = nl_langinfo(CODESET)
                 setlocale(LC_CTYPE, oldloc)
                 return result


More information about the Python-checkins mailing list