Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a24d82

Browse files
committed
Add a test for issue #1813: getlocale() failing under a Turkish locale
(not a problem under 3.x)
2 parents 8dbd857 + 0e3c5a8 commit 5a24d82

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

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):

Lib/test/test_locale.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ def test_setlocale_category(self):
391391
# crasher from bug #7419
392392
self.assertRaises(locale.Error, locale.setlocale, 12345)
393393

394+
def test_getsetlocale_issue1813(self):
395+
# Issue #1813: setting and getting the locale under a Turkish locale
396+
oldlocale = locale.getlocale()
397+
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
398+
try:
399+
locale.setlocale(locale.LC_CTYPE, 'tr_TR')
400+
except locale.Error:
401+
# Unsupported locale on this system
402+
self.skipTest('test needs Turkish locale')
403+
loc = locale.getlocale()
404+
locale.setlocale(locale.LC_CTYPE, loc)
405+
self.assertEqual(loc, locale.getlocale())
406+
394407

395408
def test_main():
396409
tests = [

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ Core and Builtins
237237
Library
238238
-------
239239

240+
- Issue #1813: Fix codec lookup under Turkish locales.
241+
240242
- Issue #12591: Improve support of "universal newlines" in the subprocess
241243
module: the piped streams can now be properly read from or written to.
242244

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)