This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: csv reader barfs encountering quote when quote_none is set
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, washirv
Priority: low Keywords:

Created on 2005-01-27 22:56 by washirv, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
csv.patch washirv, 2005-01-27 22:56 patch
Messages (2)
msg24077 - (view) Author: washington irving (washirv) Date: 2005-01-27 22:56
I'm including a python session that I cut paste from my
xterm. Essentially the problem boils down to when
QUOTE_NONE is set for the csv reader, and it encounters
a quote immediately after a separator, it assumes that
it is in a quoted field, and keeps going till it finds
the matching end quote. Either this is a bug, or the
meaning of QUOTE_NONE is not clear. My patch for it is
to check for QUOTE_NONE immediately after the
delimiter, and if so the state machine skips to
IN_FIELD state. The patch is against 2.3.3

134 wooster:~> python
Python 2.3.3 (#1, Dec 30 2004, 14:12:38) 
[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import csv
>>> 
>>> class plain_dialect(csv.Dialect):
...     delimiter="\t"
...     escapechar="\\"
...     doublequote=False
...     skipinitialspace=True
...     lineterminator="\n"
...     quoting=csv.QUOTE_NONE
...     quotechar="'"
... 
>>> csv.register_dialect("plain", plain_dialect)
>>> import StringIO
>>> s = StringIO.StringIO()
>>> w = csv.writer(s, dialect="plain")
>>> w.writerow(["foo", "'bar"])
>>> s.seek(0)
>>> s.read()
"foo\t'bar\n"
>>> s.seek(0)
>>> r = csv.reader(s, dialect="plain")
>>> r.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
_csv.Error: newline inside string
>>> 


After patching:
135 wooster:~> python
Python 2.3.3 (#1, Dec 30 2004, 14:12:38) 
[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import csv
>>> class plain_dialect(csv.Dialect):
...     delimiter="\t"
...     escapechar="\\"
...     doublequote=False
...     skipinitialspace=True
...     lineterminator="\n"
...     quoting=csv.QUOTE_NONE
...     quotechar="'"
... 
>>> csv.register_dialect("plain", plain_dialect)
>>> import StringIO
>>> s = StringIO.StringIO()
>>> w = csv.writer(s, dialect="plain")
>>> w.writerow(["foo", "'bar"])
>>> s.seek(0)
>>> s.read()
"foo\t'bar\n"
>>> s.seek(0)
>>> r = csv.reader(s, dialect="plain")
>>> r.next()
['foo', "'bar"]
>>> 
msg82176 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-15 22:33
Cannot reproduce (snippet gives correct output). As many newline
handling changes went into csv, I will close unless someone can
reproduce the bug.
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41500
2009-02-20 01:53:54ajaksu2setstatus: pending -> closed
resolution: out of date
stage: resolved
2009-02-18 01:51:35ajaksu2setstatus: open -> pending
priority: normal -> low
2009-02-15 22:33:57ajaksu2settype: behavior
messages: + msg82176
nosy: + ajaksu2
2005-01-27 22:56:37washirvcreate