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

Delta Between Two Patch Sets: Modules/_csv.c

Issue 18829: csv produces confusing error message when passed a non-string delimiter
Left Patch Set: Created 6 years, 1 month ago
Right Patch Set: Created 6 years, 1 month 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_csv.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 /* -1 length mean src is not str */ 249 if (len > 1 || (strcmp(name, "quotechar") && len==0)) {
244 if (len == -1 || len > 1) { 250 PyErr_Format(PyExc_ValueError,
245 PyErr_Format(PyExc_TypeError, 251 "\"%s\" must be an 1-character string", name);
246 "\"%s\" must be an 1-character string",
247 name);
248 return -1; 252 return -1;
249 } 253 }
250 /* PyUnicode_READY() is called in PyUnicode_GetLength() */ 254 /* PyUnicode_READY() is called in PyUnicode_GetLength() */
251 if (len > 0) 255 if (len > 0)
252 *target = PyUnicode_READ_CHAR(src, 0); 256 *target = PyUnicode_READ_CHAR(src, 0);
253 } 257 }
254 } 258 }
255 return 0; 259 return 0;
256 } 260 }
257 261
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 return NULL; 1677 return NULL;
1674 1678
1675 /* Add the CSV exception object to the module. */ 1679 /* Add the CSV exception object to the module. */
1676 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL); 1680 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
1677 if (_csvstate(module)->error_obj == NULL) 1681 if (_csvstate(module)->error_obj == NULL)
1678 return NULL; 1682 return NULL;
1679 Py_INCREF(_csvstate(module)->error_obj); 1683 Py_INCREF(_csvstate(module)->error_obj);
1680 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj); 1684 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
1681 return module; 1685 return module;
1682 } 1686 }
LEFTRIGHT

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