1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-11 01:10:37 +02:00

optimize streaming parser detection in cli

This commit is contained in:
Kelly Brazil
2022-03-03 17:50:19 -08:00
parent 6be3d3d982
commit a9f53ee258
2 changed files with 15 additions and 4 deletions

View File

@ -144,6 +144,17 @@ def _get_parser(parser_mod_name):
modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.'
return importlib.import_module(f'{modpath}{parser_mod_name}')
def _parser_is_streaming(parser):
"""
Returns True if this is a streaming parser, else False
parser is a parser module object.
"""
if getattr(parser.info, 'streaming', None):
return True
return False
def parse(
parser_mod_name: str,
data: Union[str, Iterable[str]],
@ -237,7 +248,7 @@ def standard_parser_mod_list() -> List[str]:
plist = []
for p in parsers:
parser = _get_parser(p)
if not getattr(parser.info, 'streaming', None):
if not _parser_is_streaming(parser):
plist.append(p)
return plist
@ -249,7 +260,7 @@ def streaming_parser_mod_list() -> List[str]:
plist = []
for p in parsers:
parser = _get_parser(p)
if getattr(parser.info, 'streaming', None):
if _parser_is_streaming(parser):
plist.append(p)
return plist