Fix parsing of csv files with escapes (escape character previously would be

left in stream).
This commit is contained in:
Andrew McNamara 2005-01-10 01:04:40 +00:00
parent 41e4faa82b
commit 36a7691c2d
2 changed files with 2 additions and 10 deletions

View File

@ -227,10 +227,10 @@ class Test_Csv(unittest.TestCase):
self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], []) self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], [])
def test_read_escape(self): def test_read_escape(self):
self._read_test(['a,\\b,c'], [['a', '\\b', 'c']], escapechar='\\') self._read_test(['a,\\b,c'], [['a', 'b', 'c']], escapechar='\\')
self._read_test(['a,b\\,c'], [['a', 'b,c']], escapechar='\\') self._read_test(['a,b\\,c'], [['a', 'b,c']], escapechar='\\')
self._read_test(['a,"b\\,c"'], [['a', 'b,c']], escapechar='\\') self._read_test(['a,"b\\,c"'], [['a', 'b,c']], escapechar='\\')
self._read_test(['a,"b,\\c"'], [['a', 'b,\\c']], escapechar='\\') self._read_test(['a,"b,\\c"'], [['a', 'b,c']], escapechar='\\')
self._read_test(['a,"b,c\\""'], [['a', 'b,c"']], escapechar='\\') self._read_test(['a,"b,c\\""'], [['a', 'b,c"']], escapechar='\\')
self._read_test(['a,"b,c"\\'], [['a', 'b,c\\']], escapechar='\\') self._read_test(['a,"b,c"\\'], [['a', 'b,c\\']], escapechar='\\')

View File

@ -584,10 +584,6 @@ parse_process_char(ReaderObj *self, char c)
break; break;
case ESCAPED_CHAR: case ESCAPED_CHAR:
if (c != dialect->escapechar &&
c != dialect->delimiter &&
c != dialect->quotechar)
parse_add_char(self, dialect->escapechar);
parse_add_char(self, c); parse_add_char(self, c);
self->state = IN_FIELD; self->state = IN_FIELD;
break; break;
@ -642,10 +638,6 @@ parse_process_char(ReaderObj *self, char c)
break; break;
case ESCAPE_IN_QUOTED_FIELD: case ESCAPE_IN_QUOTED_FIELD:
if (c != dialect->escapechar &&
c != dialect->delimiter &&
c != dialect->quotechar)
parse_add_char(self, dialect->escapechar);
parse_add_char(self, c); parse_add_char(self, c);
self->state = IN_QUOTED_FIELD; self->state = IN_QUOTED_FIELD;
break; break;