mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-12 03:24:23 +02:00
Fix lint error
This commit is contained in:
parent
dc9947a5e1
commit
50a979b63d
1 changed files with 23 additions and 23 deletions
|
|
@ -8,33 +8,12 @@ import itertools
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
from . import recipes
|
||||
from typing import Dict, cast, BinaryIO, Iterable, Iterator, Optional, Tuple, Type
|
||||
|
||||
|
||||
class _CloseableIterator(Iterator[dict]):
|
||||
"""Iterator wrapper that closes a file when iteration is complete."""
|
||||
|
||||
def __init__(self, iterator: Iterator[dict], closeable: io.IOBase):
|
||||
self._iterator = iterator
|
||||
self._closeable = closeable
|
||||
|
||||
def __iter__(self) -> "_CloseableIterator":
|
||||
return self
|
||||
|
||||
def __next__(self) -> dict:
|
||||
try:
|
||||
return next(self._iterator)
|
||||
except StopIteration:
|
||||
self._closeable.close()
|
||||
raise
|
||||
|
||||
def close(self) -> None:
|
||||
self._closeable.close()
|
||||
|
||||
|
||||
import click
|
||||
|
||||
from . import recipes
|
||||
|
||||
try:
|
||||
import pysqlite3 as sqlite3 # noqa: F401
|
||||
from pysqlite3 import dbapi2 # noqa: F401
|
||||
|
|
@ -65,6 +44,27 @@ SPATIALITE_PATHS = (
|
|||
ORIGINAL_CSV_FIELD_SIZE_LIMIT = csv.field_size_limit()
|
||||
|
||||
|
||||
class _CloseableIterator(Iterator[dict]):
|
||||
"""Iterator wrapper that closes a file when iteration is complete."""
|
||||
|
||||
def __init__(self, iterator: Iterator[dict], closeable: io.IOBase):
|
||||
self._iterator = iterator
|
||||
self._closeable = closeable
|
||||
|
||||
def __iter__(self) -> "_CloseableIterator":
|
||||
return self
|
||||
|
||||
def __next__(self) -> dict:
|
||||
try:
|
||||
return next(self._iterator)
|
||||
except StopIteration:
|
||||
self._closeable.close()
|
||||
raise
|
||||
|
||||
def close(self) -> None:
|
||||
self._closeable.close()
|
||||
|
||||
|
||||
def maximize_csv_field_size_limit():
|
||||
"""
|
||||
Increase the CSV field size limit to the maximum possible.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue