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

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 ago
Right Patch Set: Created 6 years 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)) { 242 if (!PyUnicode_Check(src)) {
243 PyErr_Format(PyExc_TypeError, 243 PyErr_Format(PyExc_TypeError,
244 "\"%s\" must be string, not %s", name, 244 "\"%s\" must be string, not %.200s", name,
245 src->ob_type->tp_name); 245 src->ob_type->tp_name);
246 return -1; 246 return -1;
247 } 247 }
248 len = PyUnicode_GetLength(src); 248 len = PyUnicode_GetLength(src);
249 if (len > 1) { 249 if (len > 1 || (strcmp(name, "quotechar") && len==0)) {
250 PyErr_Format(PyExc_ValueError, 250 PyErr_Format(PyExc_ValueError,
251 "\"%s\" must be an 1-character string", name); 251 "\"%s\" must be an 1-character string", name);
252 return -1; 252 return -1;
253 } 253 }
254 /* PyUnicode_READY() is called in PyUnicode_GetLength() */ 254 /* PyUnicode_READY() is called in PyUnicode_GetLength() */
255 if (len > 0) 255 if (len > 0)
256 *target = PyUnicode_READ_CHAR(src, 0); 256 *target = PyUnicode_READ_CHAR(src, 0);
257 } 257 }
258 } 258 }
259 return 0; 259 return 0;
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 return NULL; 1677 return NULL;
1678 1678
1679 /* Add the CSV exception object to the module. */ 1679 /* Add the CSV exception object to the module. */
1680 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL); 1680 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
1681 if (_csvstate(module)->error_obj == NULL) 1681 if (_csvstate(module)->error_obj == NULL)
1682 return NULL; 1682 return NULL;
1683 Py_INCREF(_csvstate(module)->error_obj); 1683 Py_INCREF(_csvstate(module)->error_obj);
1684 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj); 1684 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
1685 return module; 1685 return module;
1686 } 1686 }
LEFTRIGHT

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