Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv reader barfs encountering quote when quote_none is set #41500

Closed
washirv mannequin opened this issue Jan 27, 2005 · 2 comments
Closed

csv reader barfs encountering quote when quote_none is set #41500

washirv mannequin opened this issue Jan 27, 2005 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@washirv
Copy link
Mannequin

washirv mannequin commented Jan 27, 2005

BPO 1111100
Nosy @devdanzin
Files
  • csv.patch: patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-02-20.01:53:54.649>
    created_at = <Date 2005-01-27.22:56:37.000>
    labels = ['type-bug', 'library']
    title = 'csv reader barfs encountering quote when quote_none is set'
    updated_at = <Date 2009-02-20.01:53:54.648>
    user = 'https://bugs.python.org/washirv'

    bugs.python.org fields:

    activity = <Date 2009-02-20.01:53:54.648>
    actor = 'ajaksu2'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-02-20.01:53:54.649>
    closer = 'ajaksu2'
    components = ['Library (Lib)']
    creation = <Date 2005-01-27.22:56:37.000>
    creator = 'washirv'
    dependencies = []
    files = ['1568']
    hgrepos = []
    issue_num = 1111100
    keywords = []
    message_count = 2.0
    messages = ['24077', '82176']
    nosy_count = 2.0
    nosy_names = ['washirv', 'ajaksu2']
    pr_nums = []
    priority = 'low'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1111100'
    versions = ['Python 2.3']

    @washirv
    Copy link
    Mannequin Author

    washirv mannequin commented Jan 27, 2005

    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"]
    >>>

    @washirv washirv mannequin added the stdlib Python modules in the Lib dir label Jan 27, 2005
    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented Feb 15, 2009

    Cannot reproduce (snippet gives correct output). As many newline
    handling changes went into csv, I will close unless someone can
    reproduce the bug.

    @devdanzin devdanzin mannequin added the type-bug An unexpected behavior, bug, or error label Feb 15, 2009
    @devdanzin devdanzin mannequin closed this as completed Feb 20, 2009
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants