[Python-checkins] cpython (merge 3.2 -> default): #12266: merge with 3.2.

ezio.melotti python-checkins at python.org
Mon Aug 15 08:26:42 CEST 2011


http://hg.python.org/cpython/rev/1ea72da11724
changeset:   71868:1ea72da11724
parent:      71865:49e9e34da512
parent:      71866:c34772013c53
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Mon Aug 15 09:26:28 2011 +0300
summary:
  #12266: merge with 3.2.

files:
  Lib/test/string_tests.py |  17 +++++++++++++++++
  Misc/NEWS                |   3 +++
  Objects/unicodeobject.c  |   4 ++--
  3 files changed, 22 insertions(+), 2 deletions(-)


diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -641,6 +641,23 @@
         self.checkequal('Aaaa', 'aaaa', 'capitalize')
         self.checkequal('Aaaa', 'AaAa', 'capitalize')
 
+        # check that titlecased chars are lowered correctly
+        # \u1ffc is the titlecased char
+        self.checkequal('\u1ffc\u1ff3\u1ff3\u1ff3',
+                        '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
+        # check with cased non-letter chars
+        self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
+                        '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
+        self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
+                        '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
+        self.checkequal('\u2160\u2171\u2172',
+                        '\u2160\u2161\u2162', 'capitalize')
+        self.checkequal('\u2160\u2171\u2172',
+                        '\u2170\u2171\u2172', 'capitalize')
+        # check with Ll chars with no upper - nothing changes here
+        self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
+                        '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
+
         self.checkraises(TypeError, 'hello', 'capitalize', 42)
 
     def test_lower(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
+  titlecased and cased non-letter characters.
+
 - Issue #12732: In narrow unicode builds, allow Unicode identifiers which fall
   outside the BMP.
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6733,13 +6733,13 @@
 
     if (len == 0)
         return 0;
-    if (Py_UNICODE_ISLOWER(*s)) {
+    if (!Py_UNICODE_ISUPPER(*s)) {
         *s = Py_UNICODE_TOUPPER(*s);
         status = 1;
     }
     s++;
     while (--len > 0) {
-        if (Py_UNICODE_ISUPPER(*s)) {
+        if (!Py_UNICODE_ISLOWER(*s)) {
             *s = Py_UNICODE_TOLOWER(*s);
             status = 1;
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list