| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -175,6 +175,66 @@ def passValue(value): | |||
| 175 | 175 | self.assertEqual(passValue(f), f) | |
| 176 | 176 | self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,))) | |
| 177 | 177 | ||
| 178 | + def test_splitlist(self): | ||
| 179 | + splitlist = self.interp.tk.splitlist | ||
| 180 | + call = self.interp.tk.call | ||
| 181 | + self.assertRaises(TypeError, splitlist) | ||
| 182 | + self.assertRaises(TypeError, splitlist, 'a', 'b') | ||
| 183 | + self.assertRaises(TypeError, splitlist, 2) | ||
| 184 | + testcases = [ | ||
| 185 | + ('2', ('2',)), | ||
| 186 | + ('', ()), | ||
| 187 | + ('{}', ('',)), | ||
| 188 | + ('""', ('',)), | ||
| 189 | + ('a\n b\t\r c\n ', ('a', 'b', 'c')), | ||
| 190 | + (b'a\n b\t\r c\n ', ('a', 'b', 'c')), | ||
| 191 | + ('a \u20ac', ('a', '\u20ac')), | ||
| 192 | + (b'a \xe2\x82\xac', ('a', '\u20ac')), | ||
| 193 | + ('a {b c}', ('a', 'b c')), | ||
| 194 | + (r'a b\ c', ('a', 'b c')), | ||
| 195 | + (('a', 'b c'), ('a', 'b c')), | ||
| 196 | + ('a 2', ('a', '2')), | ||
| 197 | + (('a', 2), ('a', 2)), | ||
| 198 | + ('a 3.4', ('a', '3.4')), | ||
| 199 | + (('a', 3.4), ('a', 3.4)), | ||
| 200 | + ((), ()), | ||
| 201 | + (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), | ||
| 202 | + ] | ||
| 203 | + for arg, res in testcases: | ||
| 204 | + self.assertEqual(splitlist(arg), res, msg=arg) | ||
| 205 | + self.assertRaises(TclError, splitlist, '{') | ||
| 206 | + | ||
| 207 | + def test_split(self): | ||
| 208 | + split = self.interp.tk.split | ||
| 209 | + call = self.interp.tk.call | ||
| 210 | + self.assertRaises(TypeError, split) | ||
| 211 | + self.assertRaises(TypeError, split, 'a', 'b') | ||
| 212 | + self.assertRaises(TypeError, split, 2) | ||
| 213 | + testcases = [ | ||
| 214 | + ('2', '2'), | ||
| 215 | + ('', ''), | ||
| 216 | + ('{}', ''), | ||
| 217 | + ('""', ''), | ||
| 218 | + ('{', '{'), | ||
| 219 | + ('a\n b\t\r c\n ', ('a', 'b', 'c')), | ||
| 220 | + (b'a\n b\t\r c\n ', ('a', 'b', 'c')), | ||
| 221 | + ('a \u20ac', ('a', '\u20ac')), | ||
| 222 | + (b'a \xe2\x82\xac', ('a', '\u20ac')), | ||
| 223 | + ('a {b c}', ('a', ('b', 'c'))), | ||
| 224 | + (r'a b\ c', ('a', ('b', 'c'))), | ||
| 225 | + (('a', b'b c'), ('a', ('b', 'c'))), | ||
| 226 | + (('a', 'b c'), ('a', ('b', 'c'))), | ||
| 227 | + ('a 2', ('a', '2')), | ||
| 228 | + (('a', 2), ('a', 2)), | ||
| 229 | + ('a 3.4', ('a', '3.4')), | ||
| 230 | + (('a', 3.4), ('a', 3.4)), | ||
| 231 | + (('a', (2, 3.4)), ('a', (2, 3.4))), | ||
| 232 | + ((), ()), | ||
| 233 | + (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), | ||
| 234 | + ] | ||
| 235 | + for arg, res in testcases: | ||
| 236 | + self.assertEqual(split(arg), res, msg=arg) | ||
| 237 | + | ||
| 178 | 238 | ||
| 179 | 239 | def test_main(): | |
| 180 | 240 | support.run_unittest(TclTest, TkinterTest) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,6 +148,9 @@ Core and Builtins | |||
| 148 | 148 | Library | |
| 149 | 149 | ------- | |
| 150 | 150 | ||
| 151 | + - Issue #18101: Tcl.split() now process strings nested in a tuple as it | ||
| 152 | + do with byte strings. | ||
| 153 | + | ||
| 151 | 154 | - Issue #18116: getpass was always getting an error when testing /dev/tty, | |
| 152 | 155 | and thus was always falling back to stdin. It also leaked an open file | |
| 153 | 156 | when it did so. Both of these issues are now fixed. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -423,6 +423,21 @@ SplitObj(PyObject *arg) | |||
| 423 | 423 | return result; | |
| 424 | 424 | /* Fall through, returning arg. */ | |
| 425 | 425 | } | |
| 426 | + else if (PyUnicode_Check(arg)) { | ||
| 427 | + int argc; | ||
| 428 | + char **argv; | ||
| 429 | + char *list = PyUnicode_AsUTF8(arg); | ||
| 430 | + | ||
| 431 | + if (list == NULL || | ||
| 432 | + Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { | ||
| 433 | + Py_INCREF(arg); | ||
| 434 | + return arg; | ||
| 435 | + } | ||
| 436 | + Tcl_Free(FREECAST argv); | ||
| 437 | + if (argc > 1) | ||
| 438 | + return Split(list); | ||
| 439 | + /* Fall through, returning arg. */ | ||
| 440 | + } | ||
| 426 | 441 | else if (PyBytes_Check(arg)) { | |
| 427 | 442 | int argc; | |
| 428 | 443 | char **argv; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments