From f50dfaef45632241f8f6972fa19bb17c54a457ff Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 13 Sep 2021 18:31:52 -0700 Subject: [PATCH] use stream_error function for exceptions. raise on non -l ls output --- jc/parsers/ls_s.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/jc/parsers/ls_s.py b/jc/parsers/ls_s.py index 5fa29025..f097fdd2 100644 --- a/jc/parsers/ls_s.py +++ b/jc/parsers/ls_s.py @@ -56,11 +56,12 @@ Examples: """ import re import jc.utils +from jc.exceptions import ParseError class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.0' + version = '0.5' description = '`ls` command streaming parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -136,6 +137,9 @@ def parse(data, raw=False, quiet=False): parent = line.strip()[:-1] continue + if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', line): + raise ParseError(f'Unable to parse line: {line.strip()}') + parsed_line = line.strip().split(maxsplit=8) output_line = {} @@ -171,15 +175,4 @@ def parse(data, raw=False, quiet=False): yield _process(output_line) except Exception as e: - if not quiet: - e.args = (str(e) + '... Use the quiet option (-q) to ignore errors.',) - raise e - else: - yield { - '_meta': - { - 'success': False, - 'error': 'error parsing line', - 'line': line.strip() - } - } + yield jc.utils.stream_error(e, quiet, line)