1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

make dialect sniff behavior match non-streaming parser

This commit is contained in:
Kelly Brazil
2022-01-03 08:48:23 -08:00
parent 3a4a27e1f9
commit 5563829df2

View File

@ -113,20 +113,20 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
# first, load the first 100 lines into a list to detect the CSV dialect
for line in itertools.islice(data, 100):
temp_list.append(line)
temp_list.append(line.rstrip())
# check for Python bug that does not split on `\r` newlines from sys.stdin correctly
# https://bugs.python.org/issue45617
if len(temp_list) == 1:
raise ParseError('Unable to detect line endings. Please try the non-streaming CSV parser instead.')
sniffdata = '\n'.join(temp_list)
sniffdata = '\n'.join(temp_list)[:1024]
dialect = 'excel' # default in csv module
try:
dialect = csv.Sniffer().sniff(sniffdata)
if '""' in sniffdata:
dialect.doublequote = True
dialect.doublequote = True
except Exception:
pass