[Python-checkins] cpython (2.7): Issue #20086: Restored the use of locale-independing mapping instead of

serhiy.storchaka python-checkins at python.org
Fri Jan 17 08:28:58 CET 2014


http://hg.python.org/cpython/rev/bac50f54d357
changeset: 88515:bac50f54d357
branch: 2.7
parent: 88513:6eed57083a37
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri Jan 17 09:27:56 2014 +0200
summary:
 Issue #20086: Restored the use of locale-independing mapping instead of
locale-depending str.lower() in locale.normalize().
files:
 Lib/locale.py | 6 +++---
 Lib/test/test_locale.py | 11 +++++++----
 Misc/NEWS | 3 +++
 3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/Lib/locale.py b/Lib/locale.py
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -379,7 +379,7 @@
 # Normalize the locale name and extract the encoding and modifier
 if isinstance(localename, _unicode):
 localename = localename.encode('ascii')
- code = localename.lower()
+ code = localename.translate(_ascii_lower_map)
 if ':' in code:
 # ':' is sometimes used as encoding delimiter.
 code = code.replace(':', '.')
@@ -414,7 +414,7 @@
 #print('lookup without modifier succeeded')
 if '@' not in code:
 return code + '@' + modifier
- if code.split('@', 1)[1].lower() == modifier:
+ if code.split('@', 1)[1].translate(_ascii_lower_map) == modifier:
 return code
 #print('second lookup failed')
 
@@ -439,7 +439,7 @@
 if '@' not in code:
 return _replace_encoding(code, encoding) + '@' + modifier
 code, defmod = code.split('@', 1)
- if defmod.lower() == modifier:
+ if defmod.translate(_ascii_lower_map) == modifier:
 return _replace_encoding(code, encoding) + '@' + defmod
 
 return localename
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -471,9 +471,13 @@
 # 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:
+ for loc in ('tr_TR', 'tr_TR.UTF-8', 'tr_TR.ISO8859-9'):
+ try:
+ locale.setlocale(locale.LC_CTYPE, loc)
+ break
+ except locale.Error:
+ continue
+ else:
 # Unsupported locale on this system
 self.skipTest('test needs Turkish locale')
 loc = locale.getlocale()
@@ -482,7 +486,6 @@
 except Exception as e:
 self.fail("Failed to set locale %r (default locale is %r): %r" %
 (loc, oldlocale, e))
- print("set locale %r (default locale is %r)" % (loc, oldlocale))
 self.assertEqual(loc, locale.getlocale())
 
 def test_normalize_issue12752(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,9 @@
 Library
 -------
 
+- Issue #20086: Restored the use of locale-independing mapping instead of
+ locale-depending str.lower() in locale.normalize().
+
 - Issue #20246: Fix buffer overflow in socket.recvfrom_into.
 
 - Issue #19082: Working SimpleXMLRPCServer and xmlrpclib examples, both in
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /