mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Merge remote-tracking branch 'jdufresne/next-func'
This commit is contained in:
commit
5a3cf32fe5
|
@ -19,10 +19,7 @@ def main():
|
||||||
|
|
||||||
def iter_file_base(fn):
|
def iter_file_base(fn):
|
||||||
f = open(fn)
|
f = open(fn)
|
||||||
if sys.version_info[0] >= 3:
|
have_line = iter(f).__next__
|
||||||
have_line = iter(f).__next__
|
|
||||||
else:
|
|
||||||
have_line = iter(f).next
|
|
||||||
|
|
||||||
while not have_line().startswith('.. toctree'):
|
while not have_line().startswith('.. toctree'):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -110,16 +110,16 @@ class DictCursorBase(_cursor):
|
||||||
try:
|
try:
|
||||||
if self._prefetch:
|
if self._prefetch:
|
||||||
res = super(DictCursorBase, self).__iter__()
|
res = super(DictCursorBase, self).__iter__()
|
||||||
first = res.next()
|
first = next(res)
|
||||||
if self._query_executed:
|
if self._query_executed:
|
||||||
self._build_index()
|
self._build_index()
|
||||||
if not self._prefetch:
|
if not self._prefetch:
|
||||||
res = super(DictCursorBase, self).__iter__()
|
res = super(DictCursorBase, self).__iter__()
|
||||||
first = res.next()
|
first = next(res)
|
||||||
|
|
||||||
yield first
|
yield first
|
||||||
while 1:
|
while 1:
|
||||||
yield res.next()
|
yield next(res)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ class NamedTupleCursor(_cursor):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
try:
|
try:
|
||||||
it = super(NamedTupleCursor, self).__iter__()
|
it = super(NamedTupleCursor, self).__iter__()
|
||||||
t = it.next()
|
t = next(it)
|
||||||
|
|
||||||
nt = self.Record
|
nt = self.Record
|
||||||
if nt is None:
|
if nt is None:
|
||||||
|
@ -358,7 +358,7 @@ class NamedTupleCursor(_cursor):
|
||||||
yield nt._make(t)
|
yield nt._make(t)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
yield nt._make(it.next())
|
yield nt._make(next(it))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1144,7 +1144,7 @@ def _paginate(seq, page_size):
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
for i in xrange(page_size):
|
for i in xrange(page_size):
|
||||||
page.append(it.next())
|
page.append(next(it))
|
||||||
yield page
|
yield page
|
||||||
page = []
|
page = []
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
|
|
@ -276,7 +276,7 @@ class SQL(Composable):
|
||||||
rv = []
|
rv = []
|
||||||
it = iter(seq)
|
it = iter(seq)
|
||||||
try:
|
try:
|
||||||
rv.append(it.next())
|
rv.append(next(it))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -334,9 +334,9 @@ class CursorTests(ConnectingTestCase):
|
||||||
# timestamp will not be influenced by the pause in Python world.
|
# timestamp will not be influenced by the pause in Python world.
|
||||||
curs.execute("""select clock_timestamp() from generate_series(1,2)""")
|
curs.execute("""select clock_timestamp() from generate_series(1,2)""")
|
||||||
i = iter(curs)
|
i = iter(curs)
|
||||||
t1 = (i.next())[0] # the brackets work around a 2to3 bug
|
t1 = next(i)[0]
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
t2 = (i.next())[0]
|
t2 = next(i)[0]
|
||||||
self.assert_((t2 - t1).microseconds * 1e-6 < 0.1,
|
self.assert_((t2 - t1).microseconds * 1e-6 < 0.1,
|
||||||
"named cursor records fetched in 2 roundtrips (delta: %s)"
|
"named cursor records fetched in 2 roundtrips (delta: %s)"
|
||||||
% (t2 - t1))
|
% (t2 - t1))
|
||||||
|
|
|
@ -310,22 +310,22 @@ class NamedTupleCursorTest(ConnectingTestCase):
|
||||||
i = iter(curs)
|
i = iter(curs)
|
||||||
self.assertEqual(curs.rownumber, 0)
|
self.assertEqual(curs.rownumber, 0)
|
||||||
|
|
||||||
t = i.next()
|
t = next(i)
|
||||||
self.assertEqual(t.i, 1)
|
self.assertEqual(t.i, 1)
|
||||||
self.assertEqual(t.s, 'foo')
|
self.assertEqual(t.s, 'foo')
|
||||||
self.assertEqual(curs.rownumber, 1)
|
self.assertEqual(curs.rownumber, 1)
|
||||||
self.assertEqual(curs.rowcount, 3)
|
self.assertEqual(curs.rowcount, 3)
|
||||||
|
|
||||||
t = i.next()
|
t = next(i)
|
||||||
self.assertEqual(t.i, 2)
|
self.assertEqual(t.i, 2)
|
||||||
self.assertEqual(t.s, 'bar')
|
self.assertEqual(t.s, 'bar')
|
||||||
self.assertEqual(curs.rownumber, 2)
|
self.assertEqual(curs.rownumber, 2)
|
||||||
self.assertEqual(curs.rowcount, 3)
|
self.assertEqual(curs.rowcount, 3)
|
||||||
|
|
||||||
t = i.next()
|
t = next(i)
|
||||||
self.assertEqual(t.i, 3)
|
self.assertEqual(t.i, 3)
|
||||||
self.assertEqual(t.s, 'baz')
|
self.assertEqual(t.s, 'baz')
|
||||||
self.assertRaises(StopIteration, i.next)
|
self.assertRaises(StopIteration, next, i)
|
||||||
self.assertEqual(curs.rownumber, 3)
|
self.assertEqual(curs.rownumber, 3)
|
||||||
self.assertEqual(curs.rowcount, 3)
|
self.assertEqual(curs.rowcount, 3)
|
||||||
|
|
||||||
|
|
|
@ -344,11 +344,11 @@ class ComposedTest(ConnectingTestCase):
|
||||||
def test_iter(self):
|
def test_iter(self):
|
||||||
obj = sql.Composed([sql.SQL("foo"), sql.SQL('bar')])
|
obj = sql.Composed([sql.SQL("foo"), sql.SQL('bar')])
|
||||||
it = iter(obj)
|
it = iter(obj)
|
||||||
i = it.next()
|
i = next(it)
|
||||||
self.assertEqual(i, sql.SQL('foo'))
|
self.assertEqual(i, sql.SQL('foo'))
|
||||||
i = it.next()
|
i = next(it)
|
||||||
self.assertEqual(i, sql.SQL('bar'))
|
self.assertEqual(i, sql.SQL('bar'))
|
||||||
self.assertRaises(StopIteration, it.next)
|
self.assertRaises(StopIteration, next, it)
|
||||||
|
|
||||||
|
|
||||||
class PlaceholderTest(ConnectingTestCase):
|
class PlaceholderTest(ConnectingTestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user