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

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 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)) 242 if (!PyUnicode_Check(src)) {
243 goto err; 243 PyErr_Format(PyExc_TypeError,
244 "\"%s\" must be string, not %.200s", name,
245 src->ob_type->tp_name);
246 return -1;
247 }
244 len = PyUnicode_GetLength(src); 248 len = PyUnicode_GetLength(src);
245 if (len > 1) 249 if (len > 1 || (strcmp(name, "quotechar") && len==0)) {
246 goto err; 250 PyErr_Format(PyExc_ValueError,
251 "\"%s\" must be an 1-character string", name);
252 return -1;
253 }
247 /* PyUnicode_READY() is called in PyUnicode_GetLength() */ 254 /* PyUnicode_READY() is called in PyUnicode_GetLength() */
248 if (len > 0) 255 if (len > 0)
249 *target = PyUnicode_READ_CHAR(src, 0); 256 *target = PyUnicode_READ_CHAR(src, 0);
250 } 257 }
251 } 258 }
252 return 0; 259 return 0;
253 err:
254 PyErr_Format(PyExc_TypeError,
255 "\"%s\" must be an 1-character string", name);
256 return -1;
257 } 260 }
258 261
259 static int 262 static int
260 _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt) 263 _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
261 { 264 {
262 if (src == NULL) 265 if (src == NULL)
263 *target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL); 266 *target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL);
264 else { 267 else {
265 if (src == Py_None) 268 if (src == Py_None)
266 *target = NULL; 269 *target = NULL;
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 return NULL; 1677 return NULL;
1675 1678
1676 /* Add the CSV exception object to the module. */ 1679 /* Add the CSV exception object to the module. */
1677 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL); 1680 _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
1678 if (_csvstate(module)->error_obj == NULL) 1681 if (_csvstate(module)->error_obj == NULL)
1679 return NULL; 1682 return NULL;
1680 Py_INCREF(_csvstate(module)->error_obj); 1683 Py_INCREF(_csvstate(module)->error_obj);
1681 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj); 1684 PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
1682 return module; 1685 return module;
1683 } 1686 }
LEFTRIGHT

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