1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

extract to public jc.get_parser(parser_name) (#516)

* remove unused imports and RegEx

* extract to public jc.get_parser(parser_name)

* changed order of exports

* add doc

* add doc.md

* remove data_dir from doc.md

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
Muescha
2024-01-07 01:22:02 +01:00
committed by Kelly Brazil
parent 8614d3dde9
commit 973c535c72
3 changed files with 45 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# Table of Contents
* [jc.lib](#jc.lib)
* [get\_parser](#jc.lib.get_parser)
* [parse](#jc.lib.parse)
* [parser\_mod\_list](#jc.lib.parser_mod_list)
* [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list)
@ -17,6 +18,26 @@
jc - JSON Convert lib module
<a id="jc.lib.get_parser"></a>
### get\_parser
```python
def get_parser(parser_mod_name) -> ModuleType
```
Return the parser module object
Parameters:
parser_mod_name: (string or name of the parser module. This
Module) function will accept module_name,
cli-name, and --argument-name
variants of the module name.
Returns:
Parser: the parser module object
<a id="jc.lib.parse"></a>
### parse

View File

@ -127,6 +127,7 @@ Get a list of streaming parser module names to be used in
from .lib import (
__version__ as __version__,
parse as parse,
get_parser as get_parser,
parser_mod_list as parser_mod_list,
plugin_parser_mod_list as plugin_parser_mod_list,
standard_parser_mod_list as standard_parser_mod_list,

View File

@ -270,6 +270,28 @@ def _parser_argument(parser_mod_name: str) -> str:
parser = _modname_to_cliname(parser_mod_name)
return f'--{parser}'
def get_parser(parser_mod_name) -> ModuleType:
"""
Return the parser module object
Parameters:
parser_mod_name: (string or name of the parser module. This
Module) function will accept module_name,
cli-name, and --argument-name
variants of the module name.
Returns:
Parser: the parser module object
"""
if isinstance(parser_mod_name, ModuleType):
jc_parser = parser_mod_name
else:
jc_parser = _get_parser(parser_mod_name)
return jc_parser
def _get_parser(parser_mod_name: str) -> ModuleType:
"""Return the parser module object"""
# ensure parser_mod_name is a true module name and not a cli name
@ -409,10 +431,7 @@ def parse(
Standard Parsers: Dictionary or List of Dictionaries
Streaming Parsers: Generator Object containing Dictionaries
"""
if isinstance(parser_mod_name, ModuleType):
jc_parser = parser_mod_name
else:
jc_parser = _get_parser(parser_mod_name)
jc_parser = get_parser(parser_mod_name)
if ignore_exceptions is not None:
return jc_parser.parse(