| 192 | |
| 193 | |
| 194 | class CursorIterator(BaseCursor): |
| 195 | |
| 196 | __slots__ = ('_buffer', '_prefetch', '_timeout') |
| 197 | |
| 198 | def __init__( |
| 199 | self, |
| 200 | connection, |
| 201 | query, |
| 202 | state, |
| 203 | args, |
| 204 | record_class, |
| 205 | prefetch, |
| 206 | timeout |
| 207 | ): |
| 208 | super().__init__(connection, query, state, args, record_class) |
| 209 | |
| 210 | if prefetch <= 0: |
| 211 | raise exceptions.InterfaceError( |
| 212 | 'prefetch argument must be greater than zero') |
| 213 | |
| 214 | self._buffer = collections.deque() |
| 215 | self._prefetch = prefetch |
| 216 | self._timeout = timeout |
| 217 | |
| 218 | @connresource.guarded |
| 219 | def __aiter__(self): |
| 220 | return self |
| 221 | |
| 222 | @connresource.guarded |
| 223 | async def __anext__(self): |
| 224 | if self._state is None: |
| 225 | self._state = await self._connection._get_statement( |
| 226 | self._query, |
| 227 | self._timeout, |
| 228 | named=True, |
| 229 | record_class=self._record_class, |
| 230 | ) |
| 231 | self._state.attach() |
| 232 | |
| 233 | if not self._portal_name and not self._exhausted: |
| 234 | buffer = await self._bind_exec(self._prefetch, self._timeout) |
| 235 | self._buffer.extend(buffer) |
| 236 | |
| 237 | if not self._buffer and not self._exhausted: |
| 238 | buffer = await self._exec(self._prefetch, self._timeout) |
| 239 | self._buffer.extend(buffer) |
| 240 | |
| 241 | if self._portal_name and self._exhausted: |
| 242 | await self._close_portal(self._timeout) |
| 243 | |
| 244 | if self._buffer: |
| 245 | return self._buffer.popleft() |
| 246 | |
| 247 | raise StopAsyncIteration |
| 248 | |
| 249 | |
| 250 | class Cursor(BaseCursor): |
no outgoing calls
no test coverage detected
searching dependent graphs…