diff options
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index dcb671e..ed6055d 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -51,7 +51,7 @@ static struct PyModuleDef _csvmodule; typedef enum { START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD, IN_QUOTED_FIELD, ESCAPE_IN_QUOTED_FIELD, QUOTE_IN_QUOTED_FIELD, - EAT_CRNL + EAT_CRNL,AFTER_ESCAPED_CRNL } ParserState; typedef enum { @@ -553,7 +553,10 @@ parse_save_field(ReaderObj *self) return -1; field = tmp; } - PyList_Append(self->fields, field); + if (PyList_Append(self->fields, field) < 0) { + Py_DECREF(field); + return -1; + } Py_DECREF(field); return 0; } @@ -651,6 +654,12 @@ parse_process_char(ReaderObj *self, Py_UCS4 c) break; case ESCAPED_CHAR: + if (c == '\n' || c=='\r') { + if (parse_add_char(self, c) < 0) + return -1; + self->state = AFTER_ESCAPED_CRNL; + break; + } if (c == '\0') c = '\n'; if (parse_add_char(self, c) < 0) @@ -658,6 +667,11 @@ parse_process_char(ReaderObj *self, Py_UCS4 c) self->state = IN_FIELD; break; + case AFTER_ESCAPED_CRNL: + if (c == '\0') + break; + /*fallthru*/ + case IN_FIELD: /* in unquoted field */ if (c == '\n' || c == '\r' || c == '\0') { @@ -1564,7 +1578,7 @@ PyDoc_STRVAR(csv_reader_doc, "provided by the dialect.\n" "\n" "The returned object is an iterator. Each iteration returns a row\n" -"of the CSV file (which can span multiple input lines):\n"); +"of the CSV file (which can span multiple input lines).\n"); PyDoc_STRVAR(csv_writer_doc, " csv_writer = csv.writer(fileobj [, dialect='excel']\n" @@ -1590,7 +1604,7 @@ PyDoc_STRVAR(csv_get_dialect_doc, PyDoc_STRVAR(csv_register_dialect_doc, "Create a mapping from a string name to a dialect class.\n" -" dialect = csv.register_dialect(name, dialect)"); +" dialect = csv.register_dialect(name[, dialect[, **fmtparams]])"); PyDoc_STRVAR(csv_unregister_dialect_doc, "Delete the name/dialect mapping associated with a string name.\n" |