]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19028: Fixed tkinter.Tkapp.merge() for non-string arguments.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 23 Sep 2013 20:20:07 +0000 (23:20 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 23 Sep 2013 20:20:07 +0000 (23:20 +0300)
Lib/test/test_tcl.py
Misc/NEWS
Modules/_tkinter.c

index cf717d8ce5105ac5ec7f6c3fd188b280262cefa2..2cdac2bd972b99d1ef5a1c7b3254aeccd8dd874f 100644 (file)
@@ -254,6 +254,37 @@ class TclTest(unittest.TestCase):
         for arg, res in testcases:
             self.assertEqual(split(arg), res, msg=arg)
 
+    def test_merge(self):
+        with support.check_warnings(('merge is deprecated',
+                                     DeprecationWarning)):
+            merge = self.interp.tk.merge
+            call = self.interp.tk.call
+            testcases = [
+                ((), ''),
+                (('a',), 'a'),
+                ((2,), '2'),
+                (('',), '{}'),
+                ('{', '\\{'),
+                (('a', 'b', 'c'), 'a b c'),
+                ((' ', '\t', '\r', '\n'), '{ } {\t} {\r} {\n}'),
+                (('a', ' ', 'c'), 'a { } c'),
+                (('a', '€'), 'a €'),
+                (('a', '\U000104a2'), 'a \U000104a2'),
+                (('a', b'\xe2\x82\xac'), 'a €'),
+                (('a', ('b', 'c')), 'a {b c}'),
+                (('a', 2), 'a 2'),
+                (('a', 3.4), 'a 3.4'),
+                (('a', (2, 3.4)), 'a {2 3.4}'),
+                ((), ''),
+                ((call('list', 1, '2', (3.4,)),), '{1 2 3.4}'),
+                ((call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),),
+                    '{12 € € 3.4}'),
+            ]
+            for args, res in testcases:
+                self.assertEqual(merge(*args), res, msg=args)
+            self.assertRaises(UnicodeDecodeError, merge, b'\x80')
+            self.assertRaises(UnicodeEncodeError, merge, '\udc80')
+
 
 class BigmemTclTest(unittest.TestCase):
 
index c3d9e9ed776dc3b8fc6e02b5e3640ab447c6a090..3b232f2138eb0701ebeeb1cb69b26a48e1222c5c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -68,6 +68,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #19028: Fixed tkinter.Tkapp.merge() for non-string arguments.
+
 - Issue #3015: Fixed tkinter with wantobject=False.  Any Tcl command call
   returned empty string.
 
index 1350ff5cb95b0166e22d9ecc336e07ff5dc251b7..ecad541b9543ed1dccf370ca478dc50a541531c0 100644 (file)
@@ -331,17 +331,8 @@ AsString(PyObject *value, PyObject *tmp)
 {
     if (PyBytes_Check(value))
         return PyBytes_AsString(value);
-    else if (PyUnicode_Check(value)) {
-        PyObject *v = PyUnicode_AsUTF8String(value);
-        if (v == NULL)
-            return NULL;
-        if (PyList_Append(tmp, v) != 0) {
-            Py_DECREF(v);
-            return NULL;
-        }
-        Py_DECREF(v);
-        return PyBytes_AsString(v);
-    }
+    else if (PyUnicode_Check(value))
+        return PyUnicode_AsUTF8(value);
     else {
         PyObject *v = PyObject_Str(value);
         if (v == NULL)
@@ -351,7 +342,7 @@ AsString(PyObject *value, PyObject *tmp)
             return NULL;
         }
         Py_DECREF(v);
-        return PyBytes_AsString(v);
+        return PyUnicode_AsUTF8(v);
     }
 }