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

add input type checks

This commit is contained in:
Kelly Brazil
2021-11-30 09:19:51 -08:00
parent e395142e59
commit 8a46a259a3
2 changed files with 6 additions and 4 deletions

View File

@ -468,14 +468,16 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
"""
s = _state()
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
if not quiet: 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:
output_line = {}
try:
if not isinstance(line, str): raise TypeError("Input line must be a 'str' object.")
# skip blank lines
if line.strip() == '':
continue

View File

@ -397,7 +397,7 @@ class MyTests(unittest.TestCase):
"""
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):
data = 'unparsable data'