mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
Change WriterObj.writeline to WriterObj.write (GH-12344)
This cleans the csv module a bit, I don't think it requires a bpo issue or a news entry.
This commit is contained in:
parent
c0a1a07c7e
commit
2bc158fefe
1 changed files with 12 additions and 10 deletions
|
@ -111,7 +111,7 @@ static PyTypeObject Reader_Type;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
|
||||||
PyObject *writeline; /* write output lines to this file */
|
PyObject *write; /* write output lines to this file */
|
||||||
|
|
||||||
DialectObj *dialect; /* parsing dialect */
|
DialectObj *dialect; /* parsing dialect */
|
||||||
|
|
||||||
|
@ -1231,14 +1231,16 @@ csv_writerow(WriterObj *self, PyObject *seq)
|
||||||
|
|
||||||
/* Add line terminator.
|
/* Add line terminator.
|
||||||
*/
|
*/
|
||||||
if (!join_append_lineterminator(self))
|
if (!join_append_lineterminator(self)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
line = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
|
line = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
|
||||||
(void *) self->rec, self->rec_len);
|
(void *) self->rec, self->rec_len);
|
||||||
if (line == NULL)
|
if (line == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
result = PyObject_CallFunctionObjArgs(self->writeline, line, NULL);
|
}
|
||||||
|
result = PyObject_CallFunctionObjArgs(self->write, line, NULL);
|
||||||
Py_DECREF(line);
|
Py_DECREF(line);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1294,7 +1296,7 @@ Writer_dealloc(WriterObj *self)
|
||||||
{
|
{
|
||||||
PyObject_GC_UnTrack(self);
|
PyObject_GC_UnTrack(self);
|
||||||
Py_XDECREF(self->dialect);
|
Py_XDECREF(self->dialect);
|
||||||
Py_XDECREF(self->writeline);
|
Py_XDECREF(self->write);
|
||||||
if (self->rec != NULL)
|
if (self->rec != NULL)
|
||||||
PyMem_Free(self->rec);
|
PyMem_Free(self->rec);
|
||||||
PyObject_GC_Del(self);
|
PyObject_GC_Del(self);
|
||||||
|
@ -1304,7 +1306,7 @@ static int
|
||||||
Writer_traverse(WriterObj *self, visitproc visit, void *arg)
|
Writer_traverse(WriterObj *self, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
Py_VISIT(self->dialect);
|
Py_VISIT(self->dialect);
|
||||||
Py_VISIT(self->writeline);
|
Py_VISIT(self->write);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,7 +1314,7 @@ static int
|
||||||
Writer_clear(WriterObj *self)
|
Writer_clear(WriterObj *self)
|
||||||
{
|
{
|
||||||
Py_CLEAR(self->dialect);
|
Py_CLEAR(self->dialect);
|
||||||
Py_CLEAR(self->writeline);
|
Py_CLEAR(self->write);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,7 +1371,7 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->dialect = NULL;
|
self->dialect = NULL;
|
||||||
self->writeline = NULL;
|
self->write = NULL;
|
||||||
|
|
||||||
self->rec = NULL;
|
self->rec = NULL;
|
||||||
self->rec_size = 0;
|
self->rec_size = 0;
|
||||||
|
@ -1380,8 +1382,8 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
|
||||||
Py_DECREF(self);
|
Py_DECREF(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self->writeline = _PyObject_GetAttrId(output_file, &PyId_write);
|
self->write = _PyObject_GetAttrId(output_file, &PyId_write);
|
||||||
if (self->writeline == NULL || !PyCallable_Check(self->writeline)) {
|
if (self->write == NULL || !PyCallable_Check(self->write)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"argument 1 must have a \"write\" method");
|
"argument 1 must have a \"write\" method");
|
||||||
Py_DECREF(self);
|
Py_DECREF(self);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue