diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index b903298..62826b7 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -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.