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

move try/except inside for loop

This commit is contained in:
Kelly Brazil
2022-02-04 16:03:44 -08:00
parent fda0050d86
commit df00945b46
6 changed files with 59 additions and 49 deletions

View File

@ -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:
try:
output_line: Dict = {}
jc.utils.streaming_line_input_type_check(line)

View File

@ -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:
try:
jc.utils.streaming_line_input_type_check(line)
output_line = {}

View File

@ -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:
try:
jc.utils.streaming_line_input_type_check(line)
# skip line if it starts with 'total 1234'

View File

@ -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:
s = _state()
for line in data:
try:
output_line = {}
jc.utils.streaming_line_input_type_check(line)

View File

@ -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:
try:
jc.utils.streaming_line_input_type_check(line)
output_line: Dict = {}
@ -452,6 +451,14 @@ 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)

View File

@ -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:
try:
jc.utils.streaming_line_input_type_check(line)
line = line.rstrip()
@ -287,6 +286,14 @@ 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)