From cf9d3c08c85e659a322d24467fc972959e326c9a Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 24 Jul 2011 02:27:04 +0200 Subject: [PATCH 1/2] Issue #1813: Fix codec lookup under Turkish locales. --- Lib/test/test_codecs.py | 14 ++++++++++++++ Misc/NEWS | 2 ++ Python/codecs.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 6c7d44bec63..6b84023d236 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1,6 +1,7 @@ from test import support import unittest import codecs +import locale import sys, _testcapi, io class Queue(object): @@ -1230,6 +1231,19 @@ class CodecsModuleTest(unittest.TestCase): self.assertRaises(TypeError, codecs.getwriter) self.assertRaises(LookupError, codecs.getwriter, "__spam__") + def test_lookup_issue1813(self): + # Issue #1813: under Turkish locales, lookup of some codecs failed + # because 'I' is lowercased as "ı" (dotless i) + oldlocale = locale.getlocale(locale.LC_CTYPE) + self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) + try: + locale.setlocale(locale.LC_CTYPE, 'tr_TR') + except locale.Error: + # Unsupported locale on this system + self.skipTest('test needs Turkish locale') + c = codecs.lookup('ASCII') + self.assertEqual(c.name, 'ascii') + class StreamReaderTest(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index c7e917e045f..4513f9aec0e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -37,6 +37,8 @@ Core and Builtins Library ------- +- Issue #1813: Fix codec lookup under Turkish locales. + - Issue #12591: Improve support of "universal newlines" in the subprocess module: the piped streams can now be properly read from or written to. diff --git a/Python/codecs.c b/Python/codecs.c index 45d99291f11..1a3e45774cb 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -69,7 +69,7 @@ PyObject *normalizestring(const char *string) if (ch == ' ') ch = '-'; else - ch = tolower(Py_CHARMASK(ch)); + ch = Py_TOLOWER(Py_CHARMASK(ch)); p[i] = ch; } p[i] = '\0'; From 0e3c5a828e65f4f5821dad0e7b0ff4ca9f62f9d3 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 24 Jul 2011 02:40:25 +0200 Subject: [PATCH 2/2] Add a test for issue #1813: getlocale() failing under a Turkish locale (not a problem under 3.x) --- Lib/test/test_locale.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index e959343cca5..5155923c91a 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -391,6 +391,19 @@ class TestMiscellaneous(unittest.TestCase): # crasher from bug #7419 self.assertRaises(locale.Error, locale.setlocale, 12345) + def test_getsetlocale_issue1813(self): + # Issue #1813: setting and getting the locale under a Turkish locale + oldlocale = locale.getlocale() + self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) + try: + locale.setlocale(locale.LC_CTYPE, 'tr_TR') + except locale.Error: + # Unsupported locale on this system + self.skipTest('test needs Turkish locale') + loc = locale.getlocale() + locale.setlocale(locale.LC_CTYPE, loc) + self.assertEqual(loc, locale.getlocale()) + def test_main(): tests = [