mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
formatting
This commit is contained in:
@ -165,7 +165,7 @@ def _strip(string: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _is_separator(line: str) -> bool:
|
def _is_separator(line: str) -> bool:
|
||||||
"""Returns true if a table separator line is found"""
|
"""returns true if a table separator line is found"""
|
||||||
strip_line = line.strip()
|
strip_line = line.strip()
|
||||||
if any((
|
if any((
|
||||||
strip_line.startswith('╒') and strip_line.endswith('╕'),
|
strip_line.startswith('╒') and strip_line.endswith('╕'),
|
||||||
@ -223,7 +223,7 @@ def _snake_case(line: str) -> str:
|
|||||||
|
|
||||||
def _normalize_rows(table: str) -> List[str]:
|
def _normalize_rows(table: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Return a List row strings. Header is snake-cased
|
returns a List of row strings. Header is snake-cased
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
for line in table.splitlines():
|
for line in table.splitlines():
|
||||||
@ -257,7 +257,7 @@ def _fixup_headers(table: List[Dict]) -> List[Dict]:
|
|||||||
new_table = []
|
new_table = []
|
||||||
for row in table:
|
for row in table:
|
||||||
new_row = row.copy()
|
new_row = row.copy()
|
||||||
for k, v in row.items():
|
for k in row:
|
||||||
k_new = k
|
k_new = k
|
||||||
# remove consecutive underscores
|
# remove consecutive underscores
|
||||||
k_new = re.sub(r'__+', '_', k_new)
|
k_new = re.sub(r'__+', '_', k_new)
|
||||||
@ -268,6 +268,7 @@ def _fixup_headers(table: List[Dict]) -> List[Dict]:
|
|||||||
|
|
||||||
return new_table
|
return new_table
|
||||||
|
|
||||||
|
|
||||||
def parse(
|
def parse(
|
||||||
data: str,
|
data: str,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
|
@ -155,7 +155,7 @@ def _strip(string: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _table_sniff(string: str) -> str:
|
def _table_sniff(string: str) -> str:
|
||||||
"""Find the table-type via heuristics"""
|
"""find the table-type via heuristics"""
|
||||||
# pretty tables
|
# pretty tables
|
||||||
for line in string.splitlines():
|
for line in string.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -186,7 +186,7 @@ def _table_sniff(string: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _is_separator(line: str) -> bool:
|
def _is_separator(line: str) -> bool:
|
||||||
"""Returns true if a table separator line is found"""
|
"""returns true if a table separator line is found"""
|
||||||
strip_line = line.strip()
|
strip_line = line.strip()
|
||||||
if any((
|
if any((
|
||||||
strip_line.startswith('╒') and strip_line.endswith('╕'),
|
strip_line.startswith('╒') and strip_line.endswith('╕'),
|
||||||
@ -234,7 +234,7 @@ def _snake_case(line: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _fixup_separators(line: str) -> str:
|
def _fixup_separators(line: str) -> str:
|
||||||
"""Normalize separators, and remove first and last separators"""
|
"""normalize separators, and remove first and last separators"""
|
||||||
# normalize separator
|
# normalize separator
|
||||||
line = line.replace('│', '|')\
|
line = line.replace('│', '|')\
|
||||||
.replace('┃', '|')\
|
.replace('┃', '|')\
|
||||||
@ -258,9 +258,7 @@ def _fixup_separators(line: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _normalize_rows(table_lines: Iterable[str]) -> List[Tuple[int, List[str]]]:
|
def _normalize_rows(table_lines: Iterable[str]) -> List[Tuple[int, List[str]]]:
|
||||||
"""
|
"""return a List of tuples of row-counters and data lines."""
|
||||||
Return a List of tuples of row-counters and data lines.
|
|
||||||
"""
|
|
||||||
result = []
|
result = []
|
||||||
header_found = False
|
header_found = False
|
||||||
data_found = False
|
data_found = False
|
||||||
|
Reference in New Issue
Block a user