mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
move try/except inside for loop
This commit is contained in:
@ -120,10 +120,9 @@ def parse(
|
||||
"""
|
||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||
jc.utils.streaming_input_type_check(data)
|
||||
line = ''
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
for line in data:
|
||||
try:
|
||||
output_line: Dict = {}
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
|
||||
@ -136,9 +135,9 @@ def parse(
|
||||
else:
|
||||
raise ParseError('Not foo data')
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
@ -189,10 +189,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
headers = ''
|
||||
cpu_list = []
|
||||
device_list = []
|
||||
line = ''
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
for line in data:
|
||||
try:
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
output_line = {}
|
||||
|
||||
@ -231,9 +230,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
else:
|
||||
raise ParseError('Not iostat data')
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
@ -149,10 +149,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
jc.utils.streaming_input_type_check(data)
|
||||
|
||||
parent = ''
|
||||
line = ''
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
for line in data:
|
||||
try:
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
|
||||
# skip line if it starts with 'total 1234'
|
||||
@ -165,7 +164,7 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
|
||||
# Look for parent line if glob or -R is used
|
||||
if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', line) \
|
||||
and line.strip().endswith(':'):
|
||||
and line.strip().endswith(':'):
|
||||
parent = line.strip()[:-1]
|
||||
continue
|
||||
|
||||
@ -200,9 +199,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
|
||||
yield output_line if raw else _process(output_line)
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
@ -491,14 +491,13 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
|
||||
Iterator object
|
||||
"""
|
||||
s = _state()
|
||||
line = ''
|
||||
|
||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||
jc.utils.streaming_input_type_check(data)
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
s = _state()
|
||||
|
||||
for line in data:
|
||||
try:
|
||||
output_line = {}
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
|
||||
@ -548,9 +547,9 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
else:
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
@ -173,7 +173,6 @@ def parse(
|
||||
summary: Dict = {}
|
||||
process: str = ''
|
||||
last_process: str = ''
|
||||
line: str = ''
|
||||
|
||||
update_type = {
|
||||
'<': 'file sent',
|
||||
@ -271,8 +270,8 @@ def parse(
|
||||
stat2_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)\]\s+sent\s+(?P<sent>[\d,]+)\s+bytes\s+received\s+(?P<received>[\d,]+)\s+bytes\s+(?P<bytes_sec>[\d,.]+)\s+bytes/sec')
|
||||
stat3_line_log_v_re = re.compile(r'(?P<date>\d\d\d\d/\d\d/\d\d)\s+(?P<time>\d\d:\d\d:\d\d)\s+\[(?P<process>\d+)]\s+total\s+size\s+is\s+(?P<total_size>[\d,]+)\s+speedup\s+is\s+(?P<speedup>[\d,.]+)')
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
for line in data:
|
||||
try:
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
output_line: Dict = {}
|
||||
|
||||
@ -452,12 +451,20 @@ def parse(
|
||||
summary['speedup'] = stat3_line_log_v.group('speedup')
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
|
||||
try:
|
||||
if summary:
|
||||
yield summary if raw else _process(summary)
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
@ -157,11 +157,10 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
jc.utils.streaming_input_type_check(data)
|
||||
|
||||
output_line = {}
|
||||
line = ''
|
||||
os_type = ''
|
||||
|
||||
try:
|
||||
for line in data:
|
||||
for line in data:
|
||||
try:
|
||||
jc.utils.streaming_line_input_type_check(line)
|
||||
line = line.rstrip()
|
||||
|
||||
@ -287,13 +286,21 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
|
||||
yield output_line if raw else _process(output_line)
|
||||
output_line = {}
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
|
||||
try:
|
||||
# gather final item
|
||||
if output_line:
|
||||
yield output_line if raw else _process(output_line)
|
||||
|
||||
except Exception as e:
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
if not ignore_exceptions:
|
||||
e.args = (str(e) + ignore_exceptions_msg,)
|
||||
raise e
|
||||
|
||||
yield e, line
|
||||
yield e, line
|
||||
|
Reference in New Issue
Block a user