mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 02:13:44 +03:00
Fix DeprecationWarning: generator '__iter__' raised StopIteration
Closes #498
This commit is contained in:
parent
651f1b6c97
commit
9ffb61214c
|
@ -106,18 +106,21 @@ class DictCursorBase(_cursor):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
if self._prefetch:
|
try:
|
||||||
res = super(DictCursorBase, self).__iter__()
|
if self._prefetch:
|
||||||
first = res.next()
|
res = super(DictCursorBase, self).__iter__()
|
||||||
if self._query_executed:
|
first = res.next()
|
||||||
self._build_index()
|
if self._query_executed:
|
||||||
if not self._prefetch:
|
self._build_index()
|
||||||
res = super(DictCursorBase, self).__iter__()
|
if not self._prefetch:
|
||||||
first = res.next()
|
res = super(DictCursorBase, self).__iter__()
|
||||||
|
first = res.next()
|
||||||
|
|
||||||
yield first
|
yield first
|
||||||
while 1:
|
while 1:
|
||||||
yield res.next()
|
yield res.next()
|
||||||
|
except StopIteration:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class DictConnection(_connection):
|
class DictConnection(_connection):
|
||||||
|
@ -343,17 +346,20 @@ class NamedTupleCursor(_cursor):
|
||||||
return map(nt._make, ts)
|
return map(nt._make, ts)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
it = super(NamedTupleCursor, self).__iter__()
|
try:
|
||||||
t = it.next()
|
it = super(NamedTupleCursor, self).__iter__()
|
||||||
|
t = it.next()
|
||||||
|
|
||||||
nt = self.Record
|
nt = self.Record
|
||||||
if nt is None:
|
if nt is None:
|
||||||
nt = self.Record = self._make_nt()
|
nt = self.Record = self._make_nt()
|
||||||
|
|
||||||
yield nt._make(t)
|
yield nt._make(t)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
yield nt._make(it.next())
|
yield nt._make(it.next())
|
||||||
|
except StopIteration:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
Loading…
Reference in New Issue
Block a user