mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
Don't get too fancy with dict type annotations
This commit is contained in:
@ -44,6 +44,7 @@ else:
|
|||||||
ParserInfoType = Dict
|
ParserInfoType = Dict
|
||||||
TimeStampFormatType = Dict
|
TimeStampFormatType = Dict
|
||||||
|
|
||||||
|
|
||||||
AboutJCType = Dict[str, Union[str, int, List[ParserInfoType]]]
|
AboutJCType = Dict[str, Union[str, int, List[ParserInfoType]]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ Examples:
|
|||||||
$ foo | jc --foo -p -r
|
$ foo | jc --foo -p -r
|
||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
from typing import List
|
from typing import List, Dict
|
||||||
from jc.jc_types import JSONDictType
|
from jc.jc_types import JSONDictType
|
||||||
import jc.utils
|
import jc.utils
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ def parse(
|
|||||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||||
jc.utils.input_type_check(data)
|
jc.utils.input_type_check(data)
|
||||||
|
|
||||||
raw_output: List[JSONDictType] = []
|
raw_output: List[Dict] = []
|
||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ Examples:
|
|||||||
{example output}
|
{example output}
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
from typing import Iterable
|
from typing import Dict, Iterable
|
||||||
import jc.utils
|
import jc.utils
|
||||||
from jc.streaming import (
|
from jc.streaming import (
|
||||||
add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield
|
add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield
|
||||||
@ -115,7 +115,7 @@ def parse(
|
|||||||
for line in data:
|
for line in data:
|
||||||
try:
|
try:
|
||||||
streaming_line_input_type_check(line)
|
streaming_line_input_type_check(line)
|
||||||
output_line: JSONDictType = {}
|
output_line: Dict = {}
|
||||||
|
|
||||||
# parse the content here
|
# parse the content here
|
||||||
# check out helper functions in jc.utils
|
# check out helper functions in jc.utils
|
||||||
|
@ -32,7 +32,8 @@ Examples:
|
|||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
from typing import List, Dict
|
from typing import Dict
|
||||||
|
from jc.jc_types import JSONDictType
|
||||||
import jc.utils
|
import jc.utils
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ class info():
|
|||||||
__version__ = info.version
|
__version__ = info.version
|
||||||
|
|
||||||
|
|
||||||
def _process(proc_data: Dict) -> Dict:
|
def _process(proc_data: JSONDictType) -> JSONDictType:
|
||||||
"""
|
"""
|
||||||
Final processing to conform to the schema.
|
Final processing to conform to the schema.
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ def parse(
|
|||||||
data: str,
|
data: str,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
quiet: bool = False
|
quiet: bool = False
|
||||||
) -> Dict:
|
) -> JSONDictType:
|
||||||
"""
|
"""
|
||||||
Main text parsing function
|
Main text parsing function
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ import jc.utils
|
|||||||
from jc.streaming import (
|
from jc.streaming import (
|
||||||
add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield
|
add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield
|
||||||
)
|
)
|
||||||
from typing import Iterable
|
from typing import Dict, Iterable
|
||||||
from jc.jc_types import JSONDictType, StreamingOutputType
|
from jc.jc_types import JSONDictType, StreamingOutputType
|
||||||
from jc.exceptions import ParseError
|
from jc.exceptions import ParseError
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ def parse(
|
|||||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||||
streaming_input_type_check(data)
|
streaming_input_type_check(data)
|
||||||
|
|
||||||
output_line: JSONDictType = {}
|
output_line: Dict = {}
|
||||||
os_type = ''
|
os_type = ''
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
@ -184,15 +184,13 @@ def parse(
|
|||||||
output_line['file'] = line_list[1]
|
output_line['file'] = line_list[1]
|
||||||
|
|
||||||
# populate link_to field if -> found
|
# populate link_to field if -> found
|
||||||
file_string = output_line['file']
|
if ' -> ' in output_line['file']:
|
||||||
if isinstance(file_string, str):
|
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
|
||||||
if ' -> ' in file_string:
|
link = output_line['file'].split(' -> ')[1].strip('\u2018').rstrip('\u2019')
|
||||||
filename = file_string.split(' -> ')[0].strip('\u2018').rstrip('\u2019')
|
|
||||||
link = file_string.split(' -> ')[1].strip('\u2018').rstrip('\u2019')
|
|
||||||
output_line['file'] = filename
|
output_line['file'] = filename
|
||||||
output_line['link_to'] = link
|
output_line['link_to'] = link
|
||||||
else:
|
else:
|
||||||
filename = file_string.split(' -> ')[0].strip('\u2018').rstrip('\u2019')
|
filename = output_line['file'].split(' -> ')[0].strip('\u2018').rstrip('\u2019')
|
||||||
output_line['file'] = filename
|
output_line['file'] = filename
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user