Skip to content

Commit 3b62cc5

Browse files
committed
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.
1 parent 99dfb10 commit 3b62cc5

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

roundup/cgi/ZTUtils/Iterator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _supports(self, ob):
169169

170170
def prep_next(self, it):
171171
try:
172-
it._next = it.seq.next()
172+
it._next = next(it.seq)
173173
except StopIteration:
174174
it._prep_next = self.no_next
175175
it.end = 1
@@ -181,14 +181,16 @@ class IterIter:
181181
def __init__(self, it):
182182
self.it = it
183183
self.skip = it.nextIndex > 0 and not it.end
184-
def next(self):
184+
def __next__(self):
185185
it = self.it
186186
if self.skip:
187187
self.skip = 0
188188
return it.item
189189
if it.next():
190190
return it.item
191191
raise StopIteration
192+
# Python 2 compatibility:
193+
next = __next__
192194

193195
seqInner = SeqInner()
194196
iterInner = IterInner()

roundup/mailgw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,11 @@ def do_mailbox(self, filename):
13511351
from mailbox import UnixMailbox
13521352
mailbox = UnixMailbox(f, factory=Message)
13531353
# grab one message
1354-
message = mailbox.next()
1354+
message = next(mailbox)
13551355
while message:
13561356
# handle this message
13571357
self.handle_Message(message)
1358-
message = mailbox.next()
1358+
message = next(mailbox)
13591359
# nuke the file contents
13601360
os.ftruncate(f.fileno(), 0)
13611361
except:

roundup/support.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ def __init__(self, info, sequence):
7676

7777
def __iter__(self): return self
7878

79-
def next(self):
79+
def __next__(self):
8080
self.num += 1
8181

8282
if self.num > self.total:
8383
print(self.info, 'done', ' '*(75-len(self.info)-6))
8484
sys.stdout.flush()
85-
return self.sequence.next()
85+
return next(self.sequence)
8686

8787
if self.num % self.stepsize:
88-
return self.sequence.next()
88+
return next(self.sequence)
8989

9090
self.display()
91-
return self.sequence.next()
91+
return next(self.sequence)
92+
# Python 2 compatibility:
93+
next = __next__
9294

9395
def display(self):
9496
# figure how long we've spent - guess how long to go

0 commit comments

Comments
 (0)