summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-07-11 17:36:00 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-07-11 17:36:00 (GMT)
commit50ae3f680b43eda435daba083a1e4b41eecc4e58 (patch)
tree20d993af8eb6c7f4737e25fd6a8417c0493fec7b
parente3ed4edb94cadaef747f6032c52cd903a169883e (diff)
parent275d5fdbe40e172ab2bc99084178cb5f81334a54 (diff)
downloadcpython-50ae3f680b43eda435daba083a1e4b41eecc4e58.zip
cpython-50ae3f680b43eda435daba083a1e4b41eecc4e58.tar.gz
cpython-50ae3f680b43eda435daba083a1e4b41eecc4e58.tar.bz2
Issue #18101: Tcl.split() now process strings nested in a tuple as it
do with byte strings. Added tests for Tcl.split() and Tcl.splitline().
-rw-r--r--Lib/test/test_tcl.py60
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_tkinter.c15
3 files changed, 78 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 0cc21c9..a5aaf9b 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -175,6 +175,66 @@ class TclTest(unittest.TestCase):
self.assertEqual(passValue(f), f)
self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,)))
+ def test_splitlist(self):
+ splitlist = self.interp.tk.splitlist
+ call = self.interp.tk.call
+ self.assertRaises(TypeError, splitlist)
+ self.assertRaises(TypeError, splitlist, 'a', 'b')
+ self.assertRaises(TypeError, splitlist, 2)
+ testcases = [
+ ('2', ('2',)),
+ ('', ()),
+ ('{}', ('',)),
+ ('""', ('',)),
+ ('a\n b\t\r c\n ', ('a', 'b', 'c')),
+ (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
+ ('a \u20ac', ('a', '\u20ac')),
+ (b'a \xe2\x82\xac', ('a', '\u20ac')),
+ ('a {b c}', ('a', 'b c')),
+ (r'a b\ c', ('a', 'b c')),
+ (('a', 'b c'), ('a', 'b c')),
+ ('a 2', ('a', '2')),
+ (('a', 2), ('a', 2)),
+ ('a 3.4', ('a', '3.4')),
+ (('a', 3.4), ('a', 3.4)),
+ ((), ()),
+ (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
+ ]
+ for arg, res in testcases:
+ self.assertEqual(splitlist(arg), res, msg=arg)
+ self.assertRaises(TclError, splitlist, '{')
+
+ def test_split(self):
+ split = self.interp.tk.split
+ call = self.interp.tk.call
+ self.assertRaises(TypeError, split)
+ self.assertRaises(TypeError, split, 'a', 'b')
+ self.assertRaises(TypeError, split, 2)
+ testcases = [
+ ('2', '2'),
+ ('', ''),
+ ('{}', ''),
+ ('""', ''),
+ ('{', '{'),
+ ('a\n b\t\r c\n ', ('a', 'b', 'c')),
+ (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
+ ('a \u20ac', ('a', '\u20ac')),
+ (b'a \xe2\x82\xac', ('a', '\u20ac')),
+ ('a {b c}', ('a', ('b', 'c'))),
+ (r'a b\ c', ('a', ('b', 'c'))),
+ (('a', b'b c'), ('a', ('b', 'c'))),
+ (('a', 'b c'), ('a', ('b', 'c'))),
+ ('a 2', ('a', '2')),
+ (('a', 2), ('a', 2)),
+ ('a 3.4', ('a', '3.4')),
+ (('a', 3.4), ('a', 3.4)),
+ (('a', (2, 3.4)), ('a', (2, 3.4))),
+ ((), ()),
+ (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
+ ]
+ for arg, res in testcases:
+ self.assertEqual(split(arg), res, msg=arg)
+
def test_main():
support.run_unittest(TclTest, TkinterTest)
diff --git a/Misc/NEWS b/Misc/NEWS
index e62f05a..ea5a287 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -148,6 +148,9 @@ Core and Builtins
Library
-------
+- Issue #18101: Tcl.split() now process strings nested in a tuple as it
+ do with byte strings.
+
- Issue #18116: getpass was always getting an error when testing /dev/tty,
and thus was always falling back to stdin. It also leaked an open file
when it did so. Both of these issues are now fixed.
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index eb14827..26f10fd 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -423,6 +423,21 @@ SplitObj(PyObject *arg)
return result;
/* Fall through, returning arg. */
}
+ else if (PyUnicode_Check(arg)) {
+ int argc;
+ char **argv;
+ char *list = PyUnicode_AsUTF8(arg);
+
+ if (list == NULL ||
+ Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
+ Py_INCREF(arg);
+ return arg;
+ }
+ Tcl_Free(FREECAST argv);
+ if (argc > 1)
+ return Split(list);
+ /* Fall through, returning arg. */
+ }
else if (PyBytes_Check(arg)) {
int argc;
char **argv;