Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b4fd4d37
Commit
b4fd4d37
authored
Sep 28, 2009
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch from Thomas Barr so that csv.Sniffer will set doublequote property.
Closes issue 6606.
parent
17565e5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
Lib/csv.py
Lib/csv.py
+17
-5
Lib/test/test_csv.py
Lib/test/test_csv.py
+8
-1
No files found.
Lib/csv.py
View file @
b4fd4d37
...
...
@@ -170,7 +170,7 @@ class Sniffer:
Returns a dialect (or None) corresponding to the sample
"""
quotechar
,
delimiter
,
skipinitialspace
=
\
quotechar
,
d
oublequote
,
d
elimiter
,
skipinitialspace
=
\
self
.
_guess_quote_and_delimiter
(
sample
,
delimiters
)
if
not
delimiter
:
delimiter
,
skipinitialspace
=
self
.
_guess_delimiter
(
sample
,
...
...
@@ -184,8 +184,8 @@ class Sniffer:
lineterminator
=
'
\
r
\
n
'
quoting
=
QUOTE_MINIMAL
# escapechar = ''
doublequote
=
False
dialect
.
doublequote
=
doublequote
dialect
.
delimiter
=
delimiter
# _csv.reader won't accept a quotechar of ''
dialect
.
quotechar
=
quotechar
or
'"'
...
...
@@ -217,8 +217,8 @@ class Sniffer:
break
if
not
matches
:
return
(
''
,
None
,
0
)
# (quotechar
, delimiter, skipinitialspace)
# (quotechar, doublequote
, delimiter, skipinitialspace)
return
(
''
,
False
,
None
,
0
)
quotes
=
{}
delims
=
{}
spaces
=
0
...
...
@@ -255,7 +255,19 @@ class Sniffer:
delim
=
''
skipinitialspace
=
0
return
(
quotechar
,
delim
,
skipinitialspace
)
# if we see an extra quote between delimiters, we've got a
# double quoted format
dq_regexp
=
re
.
compile
(
r"((%(delim)s)|^)\
W*%(quo
te)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\
W*((%(delim)s)|$)
" % \
{'delim':delim, 'quote':quotechar}, re.MULTILINE)
if dq_regexp.search(data):
doublequote = True
else:
doublequote = False
return (quotechar, doublequote, delim, skipinitialspace)
def _guess_delimiter(self, data, delimiters):
...
...
Lib/test/test_csv.py
View file @
b4fd4d37
...
...
@@ -891,7 +891,7 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
'Harry''s':'Arlington Heights':'IL':'2/1/03':'Kimi Hayes'
'Shark City':'Glendale Heights':'IL':'12/28/02':'Prezence'
'Tommy''s Place':'Blue Island':'IL':'12/28/02':'Blue Sunday/White Crow'
'Stonecutters
Seafood
and Chop House':'Lemont':'IL':'12/19/02':'Week Back'
'Stonecutters
''Seafood''
and Chop House':'Lemont':'IL':'12/19/02':'Week Back'
"""
header
=
'''
\
"venue","city","state","date","performers"
...
...
@@ -950,6 +950,13 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
self
.
assertEqual
(
dialect
.
delimiter
,
"|"
)
self
.
assertEqual
(
dialect
.
quotechar
,
"'"
)
def
test_doublequote
(
self
):
sniffer
=
csv
.
Sniffer
()
dialect
=
sniffer
.
sniff
(
self
.
header
)
self
.
assertFalse
(
dialect
.
doublequote
)
dialect
=
sniffer
.
sniff
(
self
.
sample2
)
self
.
assertTrue
(
dialect
.
doublequote
)
if
not
hasattr
(
sys
,
"gettotalrefcount"
):
if
test_support
.
verbose
:
print
"*** skipping leakage tests ***"
else
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment