|
8 | 8 | import json |
9 | 9 | import os |
10 | 10 | import sys |
11 | | -from . import recipes |
12 | 11 | from typing import Dict, cast, BinaryIO, Iterable, Iterator, Optional, Tuple, Type |
13 | 12 |
|
14 | | - |
15 | | -class _CloseableIterator(Iterator[dict]): |
16 | | - """Iterator wrapper that closes a file when iteration is complete.""" |
17 | | - |
18 | | - def __init__(self, iterator: Iterator[dict], closeable: io.IOBase): |
19 | | - self._iterator = iterator |
20 | | - self._closeable = closeable |
21 | | - |
22 | | - def __iter__(self) -> "_CloseableIterator": |
23 | | - return self |
24 | | - |
25 | | - def __next__(self) -> dict: |
26 | | - try: |
27 | | - return next(self._iterator) |
28 | | - except StopIteration: |
29 | | - self._closeable.close() |
30 | | - raise |
31 | | - |
32 | | - def close(self) -> None: |
33 | | - self._closeable.close() |
34 | | - |
35 | | - |
36 | 13 | import click |
37 | 14 |
|
| 15 | +from . import recipes |
| 16 | + |
38 | 17 | try: |
39 | 18 | import pysqlite3 as sqlite3 # noqa: F401 |
40 | 19 | from pysqlite3 import dbapi2 # noqa: F401 |
@@ -65,6 +44,27 @@ def close(self) -> None: |
65 | 44 | ORIGINAL_CSV_FIELD_SIZE_LIMIT = csv.field_size_limit() |
66 | 45 |
|
67 | 46 |
|
| 47 | +class _CloseableIterator(Iterator[dict]): |
| 48 | + """Iterator wrapper that closes a file when iteration is complete.""" |
| 49 | + |
| 50 | + def __init__(self, iterator: Iterator[dict], closeable: io.IOBase): |
| 51 | + self._iterator = iterator |
| 52 | + self._closeable = closeable |
| 53 | + |
| 54 | + def __iter__(self) -> "_CloseableIterator": |
| 55 | + return self |
| 56 | + |
| 57 | + def __next__(self) -> dict: |
| 58 | + try: |
| 59 | + return next(self._iterator) |
| 60 | + except StopIteration: |
| 61 | + self._closeable.close() |
| 62 | + raise |
| 63 | + |
| 64 | + def close(self) -> None: |
| 65 | + self._closeable.close() |
| 66 | + |
| 67 | + |
68 | 68 | def maximize_csv_field_size_limit(): |
69 | 69 | """ |
70 | 70 | Increase the CSV field size limit to the maximum possible. |
|
0 commit comments