# HG changeset patch # User Joseph Myers # Date 1532473952 0 # Node ID 831787cf669468fdff1d0d4ff9b5a90cf6285515 # Parent 23b8e6067f7cdf5ff451f0a99cac4fb288e56859 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. diff -r 23b8e6067f7c -r 831787cf6694 roundup/cgi/ZTUtils/Iterator.py --- 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() diff -r 23b8e6067f7c -r 831787cf6694 roundup/mailgw.py --- a/roundup/mailgw.py Tue Jul 24 23:04:42 2018 +0000 +++ b/roundup/mailgw.py Tue Jul 24 23:12:32 2018 +0000 @@ -1351,11 +1351,11 @@ from mailbox import UnixMailbox mailbox = UnixMailbox(f, factory=Message) # grab one message - message = mailbox.next() + message = next(mailbox) while message: # handle this message self.handle_Message(message) - message = mailbox.next() + message = next(mailbox) # nuke the file contents os.ftruncate(f.fileno(), 0) except: diff -r 23b8e6067f7c -r 831787cf6694 roundup/support.py --- a/roundup/support.py Tue Jul 24 23:04:42 2018 +0000 +++ b/roundup/support.py Tue Jul 24 23:12:32 2018 +0000 @@ -76,19 +76,21 @@ def __iter__(self): return self - def next(self): + def __next__(self): self.num += 1 if self.num > self.total: print(self.info, 'done', ' '*(75-len(self.info)-6)) sys.stdout.flush() - return self.sequence.next() + return next(self.sequence) if self.num % self.stepsize: - return self.sequence.next() + return next(self.sequence) self.display() - return self.sequence.next() + return next(self.sequence) + # Python 2 compatibility: + next = __next__ def display(self): # figure how long we've spent - guess how long to go