mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-12 03:24:23 +02:00
add io.buffer in _extra_key_strategy to ensure is closed in the end
This commit is contained in:
parent
b006a4c685
commit
d3f097901c
1 changed files with 7 additions and 1 deletions
|
|
@ -212,6 +212,7 @@ def _extra_key_strategy(
|
|||
reader: Iterable[dict],
|
||||
ignore_extras: Optional[bool] = False,
|
||||
extras_key: Optional[str] = None,
|
||||
buffer: Optional[io.TextIOWrapper] = None,
|
||||
) -> Iterable[dict]:
|
||||
# Logic for handling CSV rows with more values than there are headings
|
||||
for row in reader:
|
||||
|
|
@ -231,6 +232,8 @@ def _extra_key_strategy(
|
|||
else:
|
||||
row[extras_key] = row.pop(None) # type: ignore
|
||||
yield row
|
||||
if buffer:
|
||||
buffer.close()
|
||||
|
||||
|
||||
def rows_from_file(
|
||||
|
|
@ -299,7 +302,10 @@ def rows_from_file(
|
|||
reader = csv.DictReader(decoded_fp, dialect=dialect)
|
||||
else:
|
||||
reader = csv.DictReader(decoded_fp)
|
||||
return _extra_key_strategy(reader, ignore_extras, extras_key), Format.CSV
|
||||
return (
|
||||
_extra_key_strategy(reader, ignore_extras, extras_key, decoded_fp),
|
||||
Format.CSV,
|
||||
)
|
||||
elif format == Format.TSV:
|
||||
rows = rows_from_file(
|
||||
fp, format=Format.CSV, dialect=csv.excel_tab, encoding=encoding
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue