Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(77216)

Side by Side Diff: Modules/_csv.c

Issue 18829: csv produces confusing error message when passed a non-string delimiter
Patch Set: Created 6 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_csv.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* csv module */ 1 /* csv module */
2 2
3 /* 3 /*
4 4
5 This module provides the low-level underpinnings of a CSV reading/writing 5 This module provides the low-level underpinnings of a CSV reading/writing
6 module. Users should not use this module directly, but import the csv.py 6 module. Users should not use this module directly, but import the csv.py
7 module instead. 7 module instead.
8 8
9 */ 9 */
10 10
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 static int 233 static int
234 _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt) 234 _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
235 { 235 {
236 if (src == NULL) 236 if (src == NULL)
237 *target = dflt; 237 *target = dflt;
238 else { 238 else {
239 *target = '\0'; 239 *target = '\0';
240 if (src != Py_None) { 240 if (src != Py_None) {
241 Py_ssize_t len; 241 Py_ssize_t len;
242 if (!PyUnicode_Check(src)) {
243 PyErr_Format(PyExc_TypeError,
244 "\"%s\" must be string, not %.200s", name,
245 src->ob_type->tp_name);
246 return -1;
247 }
242 len = PyUnicode_GetLength(src); 248 len = PyUnicode_GetLength(src);
243 if (len > 1) { 249 if (len > 1 || (strcmp(name, "quotechar") && len==0)) {
244 PyErr_Format(PyExc_TypeError, 250 PyErr_Format(PyExc_ValueError,
245 "\"%s\" must be an 1-character string", 251 "\"%s\" must be an 1-character string", name);
246 name);
247 return -1; 252 return -1;
248 } 253 }
249 /* PyUnicode_READY() is called in PyUnicode_GetLength() */ 254 /* PyUnicode_READY() is called in PyUnicode_GetLength() */
250 if (len > 0) 255 if (len > 0)
251 *target = PyUnicode_READ_CHAR(src, 0); 256 *target = PyUnicode_READ_CHAR(src, 0);
252 } 257 }
253 } 258 }
254 return 0; 259 return 0;
255 } 260 }
256 261
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 return NULL; 1677 return NULL;
1673 1678
1674 /* Add the CSV exception object to the module. */ 1679 /* Add the CSV exception object to the module. */
1675 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL); 1680 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
1676 if (_csvstate(module)->error_obj == NULL) 1681 if (_csvstate(module)->error_obj == NULL)
1677 return NULL; 1682 return NULL;
1678 Py_INCREF(_csvstate(module)->error_obj); 1683 Py_INCREF(_csvstate(module)->error_obj);
1679 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj); 1684 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
1680 return module; 1685 return module;
1681 } 1686 }
OLDNEW
« no previous file with comments | « Lib/test/test_csv.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+