mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add input type checks
This commit is contained in:
@ -48,7 +48,7 @@ from jc.exceptions import ParseError
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.0'
|
version = '1.1'
|
||||||
description = 'CSV file streaming parser'
|
description = 'CSV file streaming parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -95,8 +95,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
|
|
||||||
Iterator object
|
Iterator object
|
||||||
"""
|
"""
|
||||||
if not quiet:
|
if not quiet: jc.utils.compatibility(__name__, info.compatible)
|
||||||
jc.utils.compatibility(__name__, info.compatible)
|
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)):
|
||||||
|
raise TypeError("Input data must be a non-string iterable object.")
|
||||||
|
|
||||||
# convert data to an iterable in case a sequence like a list is used as input.
|
# convert data to an iterable in case a sequence like a list is used as input.
|
||||||
# this allows the exhaustion of the input so we don't double-process later.
|
# this allows the exhaustion of the input so we don't double-process later.
|
||||||
|
@ -74,7 +74,7 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test CSV parser with no data
|
Test CSV parser with no data
|
||||||
"""
|
"""
|
||||||
self.assertEqual(list(jc.parsers.csv_s.parse('', quiet=True)), [])
|
self.assertEqual(list(jc.parsers.csv_s.parse([], quiet=True)), [])
|
||||||
|
|
||||||
def test_csv_unparsable(self):
|
def test_csv_unparsable(self):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user