diff options
author | Jeroen Ruigrok van der Werven <asmodai@in-nomine.org> | 2009-05-06 05:25:42 (GMT) |
---|---|---|
committer | Jeroen Ruigrok van der Werven <asmodai@in-nomine.org> | 2009-05-06 05:25:42 (GMT) |
commit | 041f465cbd0d180426cbd5ab544266b7c06fd120 (patch) | |
tree | ace47e98347e3b88962cb57122541aece190b520 /Lib/locale.py | |
parent | eaeb4c695e5b493dcf66d381ff21a659d9388d62 (diff) | |
download | cpython-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.py | 5 |
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 |