summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2009-09-06 13:59:02 (GMT)
committerRonald Oussoren <ronaldoussoren@mac.com>2009-09-06 13:59:02 (GMT)
commit6d77e07196bfb5dfa4de6f5d80b2619c0643a75e (patch)
tree79ba3af31ea03ccc7a7969dcee6d2dadc688d5e2
parent5bbab3e64fcff14f9e21b3bc07096f443a37aa38 (diff)
downloadcpython-6d77e07196bfb5dfa4de6f5d80b2619c0643a75e.zip
cpython-6d77e07196bfb5dfa4de6f5d80b2619c0643a75e.tar.gz
cpython-6d77e07196bfb5dfa4de6f5d80b2619c0643a75e.tar.bz2
Fix for issue 6393: Python crashes on OSX when $LANG is set to some (but
not all) invalid values due to an invalid result from nl_langinfo
-rw-r--r--Lib/locale.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index 4ab3c6a..b7aaa52 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -570,10 +570,22 @@ else:
except Error:
pass
result = nl_langinfo(CODESET)
+ if not result and sys.platform == 'darwin':
+ # nl_langinfo can return an empty string
+ # when the setting has an invalid value.
+ # Default to UTF-8 in that case because
+ # UTF-8 is the default charset on OSX and
+ # returning nothing will crash the
+ # interpreter.
+ result = 'UTF-8'
+
setlocale(LC_CTYPE, oldloc)
return result
else:
- return nl_langinfo(CODESET)
+ result = nl_langinfo(CODESET)
+ if not result and sys.platform == 'darwin':
+ # See above for explanation
+ result = 'UTF-8'
### Database