Skip to content

Commit cf9d3c0

Browse files
committed
Issue #1813: Fix codec lookup under Turkish locales.
1 parent 216a3bc commit cf9d3c0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_codecs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from test import support
22
import unittest
33
import codecs
4+
import locale
45
import sys, _testcapi, io
56

67
class Queue(object):
@@ -1230,6 +1231,19 @@ def test_getwriter(self):
12301231
self.assertRaises(TypeError, codecs.getwriter)
12311232
self.assertRaises(LookupError, codecs.getwriter, "__spam__")
12321233

1234+
def test_lookup_issue1813(self):
1235+
# Issue #1813: under Turkish locales, lookup of some codecs failed
1236+
# because 'I' is lowercased as "ı" (dotless i)
1237+
oldlocale = locale.getlocale(locale.LC_CTYPE)
1238+
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
1239+
try:
1240+
locale.setlocale(locale.LC_CTYPE, 'tr_TR')
1241+
except locale.Error:
1242+
# Unsupported locale on this system
1243+
self.skipTest('test needs Turkish locale')
1244+
c = codecs.lookup('ASCII')
1245+
self.assertEqual(c.name, 'ascii')
1246+
12331247
class StreamReaderTest(unittest.TestCase):
12341248

12351249
def setUp(self):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Core and Builtins
3737
Library
3838
-------
3939

40+
- Issue #1813: Fix codec lookup under Turkish locales.
41+
4042
- Issue #12591: Improve support of "universal newlines" in the subprocess
4143
module: the piped streams can now be properly read from or written to.
4244

Python/codecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ PyObject *normalizestring(const char *string)
6969
if (ch == ' ')
7070
ch = '-';
7171
else
72-
ch = tolower(Py_CHARMASK(ch));
72+
ch = Py_TOLOWER(Py_CHARMASK(ch));
7373
p[i] = ch;
7474
}
7575
p[i] = '\0';

0 commit comments

Comments
 (0)