]> granicus.if.org Git - python/commitdiff
The simplest possible fix for the regression in bug 12752 by encoding unicodes
authorBarry Warsaw <barry@python.org>
Mon, 15 Aug 2011 23:17:12 +0000 (19:17 -0400)
committerBarry Warsaw <barry@python.org>
Mon, 15 Aug 2011 23:17:12 +0000 (19:17 -0400)
to 8-bit strings.

Lib/locale.py
Lib/test/test_locale.py

index 166538d2704e38176b3426b531ec000c630b0dad..0c4d6527e9096bcab5d4de92384d1c79ca2f113a 100644 (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.
index 718bbf40c79662081afed3032933f2256cf574d2..a88d34b2c5f924da1bbb55fdb7cb59d685778dce 100644 (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 = [