diff options
-rw-r--r-- | Lib/csv.py | 2 | ||||
-rw-r--r-- | Lib/test/test_csv.py | 10 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst | 2 |
4 files changed, 14 insertions, 1 deletions
@@ -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) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index fe24801..b65cbf6 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -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) @@ -355,6 +355,7 @@ Kushal Das Jonathan Dasteel Pierre-Yves David A. Jesse Jiryu Davis +Jake Davis Ratnadeep Debnath Merlijn van Deen John DeGood diff --git a/Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst b/Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst new file mode 100644 index 0000000..9f65193 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-02-09-14-44-43.bpo-30157.lEiiAK.rst @@ -0,0 +1,2 @@ +Fixed guessing quote and delimiter in csv.Sniffer.sniff() when only the last +field is quoted. Patch by Jake Davis. |