X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f029fb3c656788b44fa758e627592d27014528d5..0fb4fe8e4df63fd09704ca0752ed4248dab11ecd:/nominatim/db/utils.py diff --git a/nominatim/db/utils.py b/nominatim/db/utils.py index d9154ed9..57048da3 100644 --- a/nominatim/db/utils.py +++ b/nominatim/db/utils.py @@ -92,6 +92,11 @@ class CopyBuffer: return self + def size(self) -> int: + """ Return the number of bytes the buffer currently contains. + """ + return self.buffer.tell() + def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: if self.buffer is not None: self.buffer.close() @@ -115,7 +120,10 @@ class CopyBuffer: def copy_out(self, cur: Cursor, table: str, columns: Optional[Iterable[str]] = None) -> None: """ Copy all collected data into the given table. + + The buffer is empty and reusable after this operation. """ if self.buffer.tell() > 0: self.buffer.seek(0) - cur.copy_from(self.buffer, table, columns=columns) # type: ignore[arg-type] + cur.copy_from(self.buffer, table, columns=columns) + self.buffer = io.StringIO()