]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Possibly use C impl of send() and fetch() in Cursor.stream() 91/head
authorDenis Laxalde <denis@laxalde.org>
Sat, 2 Oct 2021 13:47:43 +0000 (15:47 +0200)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 5 Oct 2021 07:31:44 +0000 (09:31 +0200)
Taking advantage of these functions being available per previous commit.

psycopg/psycopg/cursor.py

index 58deeaba3de23428d0885fac648ea1a29b87ec59..86272d8fa677182e6502964d99bd25d69aa0e2f3 100644 (file)
@@ -13,7 +13,6 @@ from contextlib import contextmanager
 from . import pq
 from . import adapt
 from . import errors as e
-from . import generators
 
 from .pq import ExecStatus, Format
 from .abc import ConnectionType, Query, Params, PQGen
@@ -34,9 +33,15 @@ execute: Callable[["PGconn"], PQGen[List["PGresult"]]]
 
 if _psycopg:
     execute = _psycopg.execute
+    fetch = _psycopg.fetch
+    send = _psycopg.send
 
 else:
+    from . import generators
+
     execute = generators.execute
+    fetch = generators.fetch
+    send = generators.send
 
 
 class BaseCursor(Generic[ConnectionType, Row]):
@@ -270,8 +275,8 @@ class BaseCursor(Generic[ConnectionType, Row]):
         self._last_query = query
 
     def _stream_fetchone_gen(self, first: bool) -> PQGen[Optional["PGresult"]]:
-        yield from generators.send(self._pgconn)
-        res = yield from generators.fetch(self._pgconn)
+        yield from send(self._pgconn)
+        res = yield from fetch(self._pgconn)
         if res is None:
             return None
 
@@ -286,7 +291,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
             # End of single row results
             status = res.status
             while res:
-                res = yield from generators.fetch(self._pgconn)
+                res = yield from fetch(self._pgconn)
             if status != ExecStatus.TUPLES_OK:
                 raise e.ProgrammingError(
                     "the operation in stream() didn't produce a result"