diff -r b6ebc726d5fe Lib/locale.py --- a/Lib/locale.py Sat Jul 06 13:25:44 2013 +0200 +++ b/Lib/locale.py Sat Jul 06 14:10:50 2013 +0200 @@ -430,6 +430,8 @@ return tuple(code.split('.')[:2]) elif code == 'C': return None, None + elif code == 'UTF-8': + return None, code raise ValueError('unknown locale: %s' % localename) def _build_localename(localetuple): diff -r b6ebc726d5fe Lib/test/test_locale.py --- a/Lib/test/test_locale.py Sat Jul 06 13:25:44 2013 +0200 +++ b/Lib/test/test_locale.py Sat Jul 06 14:10:50 2013 +0200 @@ -414,6 +414,13 @@ with self.assertRaises(TypeError): locale.setlocale(locale.LC_ALL, (b'not', b'valid')) + def test_parse_utf8_locale(self): + """ On Mac OS X with default language set to English, the default + terminal sets the LC_CTYPE variable to UTF-8. Make sure we can + parse this value rather than fail. + """ + self.assertEqual((None, 'UTF-8'), locale._parse_localename('UTF-8')) + def test_main(): tests = [