[pypy-commit] pypy py3.5: Add new state to csv parsing (reubano and plan_rich)

reu...@gmail.com pypy.commits at gmail.com
Sat Oct 8 12:37:42 EDT 2016


Author: reubano at gmail.com
Branch: py3.5
Changeset: r87628:d13786edd6f2
Date: 2016-10-08 19:37 +0300
http://bitbucket.org/pypy/pypy/changeset/d13786edd6f2/

Log:	Add new state to csv parsing (reubano and plan_rich)

diff --git a/pypy/module/_csv/interp_reader.py b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -10,7 +10,7 @@
 
 (START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD,
  IN_QUOTED_FIELD, ESCAPE_IN_QUOTED_FIELD, QUOTE_IN_QUOTED_FIELD,
- EAT_CRNL) = range(8)
+ EAT_CRNL, AFTER_ESCAPED_CRNL) = range(9)
 
 
 class W_Reader(W_Root):
@@ -113,10 +113,14 @@
                         state = IN_FIELD
 
                 elif state == ESCAPED_CHAR:
-                    self.add_char(field_builder, c)
-                    state = IN_FIELD
+                    if c in '\n\r':
+                        self.add_char(field_builder, c)
+                        state = AFTER_ESCAPED_CRNL
+                    else:
+                        self.add_char(field_builder, c)
+                        state = IN_FIELD
 
-                elif state == IN_FIELD:
+                elif state == IN_FIELD or state == AFTER_ESCAPED_CRNL:
                     # in unquoted field
                     if c == u'\n' or c == u'\r':
                         # end of line


More information about the pypy-commit mailing list