self._read_test(['1,",3,",5'], [['1', '"', '3', '"', '5']],
quoting=csv.QUOTE_NONE, escapechar='\\')
# will this fail where locale uses comma for decimals?
- self._read_test([',3,"5",7.3'], [['', 3, '5', 7.3]],
+ self._read_test([',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]],
quoting=csv.QUOTE_NONNUMERIC)
self.assertRaises(ValueError, self._read_test,
['abc,3'], [[]],
finally:
csv.field_size_limit(limit)
+ def test_read_linenum(self):
+ r = csv.reader(['line,1', 'line,2', 'line,3'])
+ self.assertEqual(r.line_num, 0)
+ r.next()
+ self.assertEqual(r.line_num, 1)
+ r.next()
+ self.assertEqual(r.line_num, 2)
+ r.next()
+ self.assertEqual(r.line_num, 3)
+ self.assertRaises(StopIteration, r.next)
+ self.assertEqual(r.line_num, 3)
+
class TestDialectRegistry(unittest.TestCase):
def test_registry_badargs(self):
self.assertRaises(TypeError, csv.list_dialects, None)
+ A new module method csv.field_size_limit() has been added that sets
the parser field size limit (returning the former limit). The initial
limit is 128kB.
+ + A line_num attribute has been added to the reader object, which tracks
+ the number of lines read from the source iterator. This is not
+ the same as the number of records returned, as records can span
+ multiple lines.
+ reader and writer objects were not being registered with the cyclic-GC.
This has been fixed.
int field_len; /* length of current field */
int had_parse_error; /* did we have a parse error? */
int numeric_field; /* treat field as numeric */
+ unsigned long line_num; /* Source-file line number */
} ReaderObj;
staticforward PyTypeObject Reader_Type;
static struct PyMemberDef Reader_memberlist[] = {
{ "dialect", T_OBJECT, R_OFF(dialect), RO },
+ { "line_num", T_ULONG, R_OFF(line_num), RO },
{ NULL }
};
"newline inside string");
return NULL;
}
+ ++self->line_num;
if (self->had_parse_error)
if (parse_reset(self) < 0) {
self->input_iter = NULL;
self->field = NULL;
self->field_size = 0;
+ self->line_num = 0;
if (parse_reset(self) < 0) {
Py_DECREF(self);