summaryrefslogtreecommitdiffstats
path: root/Lib/locale.py
diff options
context:
space:
mode:
authorJeroen Ruigrok van der Werven <asmodai@in-nomine.org>2009-05-06 05:25:42 (GMT)
committerJeroen Ruigrok van der Werven <asmodai@in-nomine.org>2009-05-06 05:25:42 (GMT)
commit041f465cbd0d180426cbd5ab544266b7c06fd120 (patch)
treeace47e98347e3b88962cb57122541aece190b520 /Lib/locale.py
parenteaeb4c695e5b493dcf66d381ff21a659d9388d62 (diff)
downloadcpython-041f465cbd0d180426cbd5ab544266b7c06fd120.zip
cpython-041f465cbd0d180426cbd5ab544266b7c06fd120.tar.gz
cpython-041f465cbd0d180426cbd5ab544266b7c06fd120.tar.bz2
Wrap getpreferredencoding()'s use of setlocale in a try/except to prevent
us from raising an exception when the locale is invalid. Issue #1443504
Diffstat (limited to 'Lib/locale.py')
-rw-r--r--Lib/locale.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index 777bb03..f44effe 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -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