1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-23 00:29:59 +02:00

raise ParseError on newline bug

This commit is contained in:
Kelly Brazil
2021-10-26 07:36:23 -07:00
parent 46f568414a
commit 3ab9b43a2e

View File

@ -41,6 +41,7 @@ import itertools
import csv import csv
import jc.utils import jc.utils
from jc.utils import stream_success, stream_error from jc.utils import stream_success, stream_error
from jc.exceptions import ParseError
class info(): class info():
@ -104,10 +105,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
for line in itertools.islice(data, 100): for line in itertools.islice(data, 100):
temp_list.append(line) temp_list.append(line)
# if length of temp_list is only 1, then was probably piped in with incorrect newline for the platform # check for Python bug that does not split on `\r` newlines from sys.stdin correctly
# try splitting on lines again:
if len(temp_list) == 1: if len(temp_list) == 1:
temp_list = temp_list[0].splitlines() 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)