]> granicus.if.org Git - python/commitdiff
Wrap getpreferredencoding()'s use of setlocale in a try/except to prevent
authorJeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Wed, 6 May 2009 05:25:42 +0000 (05:25 +0000)
committerJeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Wed, 6 May 2009 05:25:42 +0000 (05:25 +0000)
us from raising an exception when the locale is invalid.

Issue #1443504

Lib/locale.py

index 777bb03f4fba0203cd710aa87c4cde89743eea84..f44effe6d270ccfcf80d0c8e69d0c989fbb426ec 100644 (file)
@@ -553,7 +553,10 @@ else:
             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