diff roundup/cgi/ZTUtils/Iterator.py @ 5396:831787cf6694

Python 3 preparation: update next() usage for iterators. Tool-assisted patch. Note that various classes in TAL code with next() methods are not actually Python iterators and so are not changed in this patch, but roundup/cgi/ZTUtils/Iterator.py includes the IterIter class which converts between the two styles of iterator.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 23:12:32 +0000
parents 35ea9b1efc14
children ef6631409171
line wrap: on
line diff
--- a/roundup/cgi/ZTUtils/Iterator.py	Tue Jul 24 23:04:42 2018 +0000
+++ b/roundup/cgi/ZTUtils/Iterator.py	Tue Jul 24 23:12:32 2018 +0000
@@ -169,7 +169,7 @@
 
     def prep_next(self, it):
         try:
-            it._next = it.seq.next()
+            it._next = next(it.seq)
         except StopIteration:
             it._prep_next = self.no_next
             it.end = 1
@@ -181,7 +181,7 @@
     def __init__(self, it):
         self.it = it
         self.skip = it.nextIndex > 0 and not it.end
-    def next(self):
+    def __next__(self):
         it = self.it
         if self.skip:
             self.skip = 0
@@ -189,6 +189,8 @@
         if it.next():
             return it.item
         raise StopIteration
+    # Python 2 compatibility:
+    next = __next__
 
 seqInner = SeqInner()
 iterInner = IterInner()

Roundup Issue Tracker: http://roundup-tracker.org/