1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

use jc.utils type checks

This commit is contained in:
Kelly Brazil
2021-11-30 11:49:40 -08:00
parent 12d2de2282
commit e8e4b46021
5 changed files with 14 additions and 19 deletions

View File

@ -95,9 +95,8 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
Iterator object Iterator object
""" """
if not quiet: jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible, quiet)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)): jc.utils.streaming_input_type_check(data)
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.

View File

@ -97,14 +97,13 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
Iterator object Iterator object
""" """
if not quiet: jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible, quiet)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)): jc.utils.streaming_input_type_check(data)
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.") jc.utils.streaming_line_input_type_check(line)
# #
# parse the input here # parse the input here

View File

@ -123,15 +123,14 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
Iterator object Iterator object
""" """
if not quiet: jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible, quiet)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)): jc.utils.streaming_input_type_check(data)
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.") jc.utils.streaming_line_input_type_check(line)
# 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):

View File

@ -468,14 +468,13 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
""" """
s = _state() s = _state()
if not quiet: jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible, quiet)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)): jc.utils.streaming_input_type_check(data)
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.") jc.utils.streaming_line_input_type_check(line)
# skip blank lines # skip blank lines
if line.strip() == '': if line.strip() == '':

View File

@ -145,9 +145,8 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
Iterator object Iterator object
""" """
if not quiet: jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible, quiet)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)): jc.utils.streaming_input_type_check(data)
raise TypeError("Input data must be a non-string iterable object.")
procs = None procs = None
buff_cache = None buff_cache = None
@ -158,7 +157,7 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
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.") jc.utils.streaming_line_input_type_check(line)
# skip blank lines # skip blank lines
if line.strip() == '': if line.strip() == '':