The simplest possible fix for the regression in bug 12752 by encoding unicodes

to 8-bit strings.
This commit is contained in:
Barry Warsaw 2011-08-15 19:17:12 -04:00
parent 5085e8ac67
commit edfba8244c
2 changed files with 7 additions and 0 deletions

View File

@ -355,6 +355,8 @@ def normalize(localename):
"""
# Normalize the locale name and extract the encoding
if isinstance(localename, unicode):
localename = localename.encode('ascii')
fullname = localename.translate(_ascii_lower_map)
if ':' in fullname:
# ':' is sometimes used as encoding delimiter.

View File

@ -412,6 +412,11 @@ class TestMiscellaneous(unittest.TestCase):
locale.setlocale(locale.LC_CTYPE, loc)
self.assertEqual(loc, locale.getlocale())
def test_normalize_issue12752(self):
# Issue #1813 caused a regression where locale.normalize() would no
# longer accept unicode strings.
self.assertEqual(locale.normalize(u'en_US'), 'en_US.ISO8859-1')
def test_main():
tests = [