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:
@ -123,13 +123,15 @@ 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.")
|
||||||
|
|
||||||
parent = ''
|
parent = ''
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
try:
|
try:
|
||||||
|
if not isinstance(line, str): raise TypeError("Input line must be a 'str' object.")
|
||||||
|
|
||||||
# skip line if it starts with 'total 1234'
|
# skip line if it starts with 'total 1234'
|
||||||
if re.match(r'total [0-9]+', line):
|
if re.match(r'total [0-9]+', line):
|
||||||
|
@ -103,7 +103,7 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test plain 'ls' on an empty directory
|
Test plain 'ls' on an empty directory
|
||||||
"""
|
"""
|
||||||
self.assertEqual(list(jc.parsers.ls_s.parse('', quiet=True)), [])
|
self.assertEqual(list(jc.parsers.ls_s.parse([], quiet=True)), [])
|
||||||
|
|
||||||
def test_ls_s_centos_7_7_raise_exception(self):
|
def test_ls_s_centos_7_7_raise_exception(self):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user