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
2411292b
Commit
2411292b
authored
Feb 09, 2018
by
Serhiy Storchaka
Committed by
GitHub
Feb 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30157: Fix csv.Sniffer.sniff() regex pattern. (GH-5601)
Co-authored-by:
Jake Davis
<
jcdavis@awedge.net
>
parent
bfe4fd5f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
1 deletion
+14
-1
Lib/csv.py
Lib/csv.py
+1
-1
Lib/test/test_csv.py
Lib/test/test_csv.py
+10
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst
...S.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst
+2
-0
No files found.
Lib/csv.py
View file @
2411292b
...
...
@@ -217,7 +217,7 @@ class Sniffer:
matches
=
[]
for
restr
in
(
r'(?P<delim>[^\
w
\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)'
,
# ,".*?",
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\
w
\n"\'])(?P<space> ?)'
,
# ".*?",
r'(?P<delim>
>[^\
w
\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'
,
# ,".*?"
r'(?P<delim>
[^\
w
\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'
,
# ,".*?"
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'
):
# ".*?" (no delim, no space)
regexp
=
re
.
compile
(
restr
,
re
.
DOTALL
|
re
.
MULTILINE
)
matches
=
regexp
.
findall
(
data
)
...
...
Lib/test/test_csv.py
View file @
2411292b
...
...
@@ -986,6 +986,16 @@ Stonecutters Seafood and Chop House+ Lemont+ IL+ 12/19/02+ Week Back
self
.
assertEqual
(
sniffer
.
has_header
(
self
.
header2
+
self
.
sample8
),
True
)
def
test_guess_quote_and_delimiter
(
self
):
sniffer
=
csv
.
Sniffer
()
for
header
in
(
";'123;4';"
,
"'123;4';"
,
";'123;4'"
,
"'123;4'"
):
with
self
.
subTest
(
header
):
dialect
=
sniffer
.
sniff
(
header
,
",;"
)
self
.
assertEqual
(
dialect
.
delimiter
,
';'
)
self
.
assertEqual
(
dialect
.
quotechar
,
"'"
)
self
.
assertIs
(
dialect
.
doublequote
,
False
)
self
.
assertIs
(
dialect
.
skipinitialspace
,
False
)
def
test_sniff
(
self
):
sniffer
=
csv
.
Sniffer
()
dialect
=
sniffer
.
sniff
(
self
.
sample1
)
...
...
Misc/ACKS
View file @
2411292b
...
...
@@ -355,6 +355,7 @@ Kushal Das
Jonathan Dasteel
Pierre-Yves David
A. Jesse Jiryu Davis
Jake Davis
Ratnadeep Debnath
Merlijn van Deen
John DeGood
...
...
Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst
0 → 100644
View file @
2411292b
Fixed guessing quote and delimiter in csv.Sniffer.sniff() when only the last
field is quoted. Patch by Jake Davis.
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