mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
add input type checks
This commit is contained in:
@ -468,14 +468,16 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
|||||||
"""
|
"""
|
||||||
s = _state()
|
s = _state()
|
||||||
|
|
||||||
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.")
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
|
||||||
output_line = {}
|
output_line = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not isinstance(line, str): raise TypeError("Input line must be a 'str' object.")
|
||||||
|
|
||||||
# skip blank lines
|
# skip blank lines
|
||||||
if line.strip() == '':
|
if line.strip() == '':
|
||||||
continue
|
continue
|
||||||
|
@ -397,7 +397,7 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test 'ping' with no data
|
Test 'ping' with no data
|
||||||
"""
|
"""
|
||||||
self.assertEqual(list(jc.parsers.ping_s.parse('', quiet=True)), [])
|
self.assertEqual(list(jc.parsers.ping_s.parse([], quiet=True)), [])
|
||||||
|
|
||||||
def test_ping_s_unparsable(self):
|
def test_ping_s_unparsable(self):
|
||||||
data = 'unparsable data'
|
data = 'unparsable data'
|
||||||
|
Reference in New Issue
Block a user