[PATCH 2 of 3] py3: convert to next() function

timeless timeless at fmr.im
Mon May 16 17:54:38 EDT 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1463434253 0
#      Mon May 16 21:30:53 2016 +0000
# Node ID bbcfd471e0c5281f97046627967e85fd2f96d2a6
# Parent  41e57b118c22aa02c80c91903a0774c5f8581463
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r bbcfd471e0c5
py3: convert to next() function

next(..) was introduced in py2.6 and .next() is not available in py3

https://docs.python.org/2/library/functions.html#next

diff -r 41e57b118c22 -r bbcfd471e0c5 contrib/synthrepo.py
--- a/contrib/synthrepo.py	Mon May 16 21:30:32 2016 +0000
+++ b/contrib/synthrepo.py	Mon May 16 21:30:53 2016 +0000
@@ -506,7 +506,7 @@
             head = rename(head)
         else:
             head = ''
-        renamed = os.path.join(head, wordgen.next())
+        renamed = os.path.join(head, next(wordgen))
         replacements[dirpath] = renamed
         return renamed
     result = []
diff -r 41e57b118c22 -r bbcfd471e0c5 doc/hgmanpage.py
--- a/doc/hgmanpage.py	Mon May 16 21:30:32 2016 +0000
+++ b/doc/hgmanpage.py	Mon May 16 21:30:53 2016 +0000
@@ -793,7 +793,7 @@
     def visit_list_item(self, node):
         # man 7 man argues to use ".IP" instead of ".TP"
         self.body.append('.IP %s %d\n' % (
-                self._list_char[-1].next(),
+                next(self._list_char[-1]),
                 self._list_char[-1].get_width(),))
 
     def depart_list_item(self, node):
diff -r 41e57b118c22 -r bbcfd471e0c5 hgext/highlight/highlight.py
--- a/hgext/highlight/highlight.py	Mon May 16 21:30:32 2016 +0000
+++ b/hgext/highlight/highlight.py	Mon May 16 21:30:53 2016 +0000
@@ -68,7 +68,7 @@
     coloriter = (s.encode(encoding.encoding, 'replace')
                  for s in colorized.splitlines())
 
-    tmpl.filters['colorize'] = lambda x: coloriter.next()
+    tmpl.filters['colorize'] = lambda x: next(coloriter)
 
     oldl = tmpl.cache[field]
     newl = oldl.replace('line|escape', 'line|colorize')
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/ancestor.py
--- a/mercurial/ancestor.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/ancestor.py	Mon May 16 21:30:53 2016 +0000
@@ -291,7 +291,7 @@
     def __nonzero__(self):
         """False if the set is empty, True otherwise."""
         try:
-            iter(self).next()
+            next(iter(self))
             return True
         except StopIteration:
             return False
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/cmdutil.py	Mon May 16 21:30:53 2016 +0000
@@ -1998,7 +1998,7 @@
         followfirst = 0
     # --follow with FILE behavior depends on revs...
     it = iter(revs)
-    startrev = it.next()
+    startrev = next(it)
     followdescendants = startrev < next(it, startrev)
 
     # branch and only_branch are really aliases and must be handled at
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/copies.py
--- a/mercurial/copies.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/copies.py	Mon May 16 21:30:53 2016 +0000
@@ -484,16 +484,16 @@
             f1r, f2r = f1.linkrev(), f2.linkrev()
 
             if f1r is None:
-                f1 = g1.next()
+                f1 = next(g1)
             if f2r is None:
-                f2 = g2.next()
+                f2 = next(g2)
 
             while True:
                 f1r, f2r = f1.linkrev(), f2.linkrev()
                 if f1r > f2r:
-                    f1 = g1.next()
+                    f1 = next(g1)
                 elif f2r > f1r:
-                    f2 = g2.next()
+                    f2 = next(g2)
                 elif f1 == f2:
                     return f1 # a match
                 elif f1r == f2r or f1r < limit or f2r < limit:
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/hgweb/webcommands.py	Mon May 16 21:30:53 2016 +0000
@@ -139,7 +139,7 @@
             yield {"line": t,
                    "lineid": "l%d" % (lineno + 1),
                    "linenumber": "% 6d" % (lineno + 1),
-                   "parity": parity.next()}
+                   "parity": next(parity)}
 
     return tmpl("filerevision",
                 file=f,
@@ -278,7 +278,7 @@
             files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
 
             yield tmpl('searchentry',
-                       parity=parity.next(),
+                       parity=next(parity),
                        changelogtag=showtags,
                        files=files,
                        **webutil.commonentry(web.repo, ctx))
@@ -375,7 +375,7 @@
                 break
 
             entry = webutil.changelistentry(web, web.repo[rev], tmpl)
-            entry['parity'] = parity.next()
+            entry['parity'] = next(parity)
             yield entry
 
     if shortlog:
@@ -527,7 +527,7 @@
 
             fctx = ctx.filectx(full)
             yield {"file": full,
-                   "parity": parity.next(),
+                   "parity": next(parity),
                    "basename": f,
                    "date": fctx.date(),
                    "size": fctx.size(),
@@ -545,7 +545,7 @@
                 h = v
 
             path = "%s%s" % (abspath, d)
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "path": path,
                    "emptydirs": "/".join(emptydirs),
                    "basename": d}
@@ -554,7 +554,7 @@
                 symrev=symrev,
                 path=abspath,
                 up=webutil.up(abspath),
-                upparity=parity.next(),
+                upparity=next(parity),
                 fentries=filelist,
                 dentries=dirlist,
                 archives=web.archivelist(hex(node)),
@@ -582,7 +582,7 @@
         if latestonly:
             t = t[:1]
         for k, n in t:
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "tag": k,
                    "date": web.repo[n].date(),
                    "node": hex(n)}
@@ -615,7 +615,7 @@
         if latestonly:
             t = i[:1]
         for k, n in t:
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "bookmark": k,
                    "date": web.repo[n].date(),
                    "node": hex(n)}
@@ -677,7 +677,7 @@
                 break
 
             yield tmpl("tagentry",
-                       parity=parity.next(),
+                       parity=next(parity),
                        tag=k,
                        node=hex(n),
                        date=web.repo[n].date())
@@ -688,7 +688,7 @@
         sortkey = lambda b: (web.repo[b[1]].rev(), b[0])
         marks = sorted(marks, key=sortkey, reverse=True)
         for k, n in marks[:10]:  # limit to 10 bookmarks
-            yield {'parity': parity.next(),
+            yield {'parity': next(parity),
                    'bookmark': k,
                    'date': web.repo[n].date(),
                    'node': hex(n)}
@@ -704,7 +704,7 @@
 
             l.append(tmpl(
                 'shortlogentry',
-                parity=parity.next(),
+                parity=next(parity),
                 **webutil.commonentry(web.repo, ctx)))
 
         l.reverse()
@@ -879,7 +879,7 @@
             if last != fnode:
                 last = fnode
 
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "node": f.hex(),
                    "rev": f.rev(),
                    "author": f.user(),
@@ -963,7 +963,7 @@
             iterfctx = fctx.filectx(i)
 
             l.append(dict(
-                parity=parity.next(),
+                parity=next(parity),
                 filerev=i,
                 file=f,
                 rename=webutil.renamelink(iterfctx),
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/hgweb/webutil.py	Mon May 16 21:30:53 2016 +0000
@@ -75,7 +75,7 @@
     def _first(self):
         """return the minimum non-filtered changeset or None"""
         try:
-            return iter(self._revlog).next()
+            return next(iter(self._revlog))
         except StopIteration:
             return None
 
@@ -247,7 +247,7 @@
             else:
                 status = 'open'
             yield {
-                'parity': parity.next(),
+                'parity': next(parity),
                 'branch': ctx.branch(),
                 'status': status,
                 'node': ctx.hex(),
@@ -369,7 +369,7 @@
         template = f in ctx and 'filenodelink' or 'filenolink'
         files.append(tmpl(template,
                           node=ctx.hex(), file=f, blockno=blockno + 1,
-                          parity=parity.next()))
+                          parity=next(parity)))
 
     basectx = basechangectx(web.repo, req)
     if basectx is None:
@@ -450,15 +450,15 @@
     block = []
     for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
         if chunk.startswith('diff') and block:
-            blockno = blockcount.next()
-            yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
+            blockno = next(blockcount)
+            yield tmpl('diffblock', parity=next(parity), blockno=blockno,
                        lines=prettyprintlines(''.join(block), blockno))
             block = []
         if chunk.startswith('diff') and style != 'raw':
             chunk = ''.join(chunk.splitlines(True)[1:])
         block.append(chunk)
-    blockno = blockcount.next()
-    yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
+    blockno = next(blockcount)
+    yield tmpl('diffblock', parity=next(parity), blockno=blockno,
                lines=prettyprintlines(''.join(block), blockno))
 
 def compare(tmpl, context, leftlines, rightlines):
@@ -521,14 +521,14 @@
 def diffsummary(statgen):
     '''Return a short summary of the diff.'''
 
-    stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next()
+    stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
     return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % (
              len(stats), addtotal, removetotal)
 
 def diffstat(tmpl, ctx, statgen, parity):
     '''Return a diffstat template for each file in the diff.'''
 
-    stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next()
+    stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
     files = ctx.files()
 
     def pct(i):
@@ -543,7 +543,7 @@
         fileno += 1
         yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno,
                    total=total, addpct=pct(adds), removepct=pct(removes),
-                   parity=parity.next())
+                   parity=next(parity))
 
 class sessionvars(object):
     def __init__(self, vars, start='?'):
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/merge.py
--- a/mercurial/merge.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/merge.py	Mon May 16 21:30:53 2016 +0000
@@ -373,7 +373,7 @@
         """Write current state on disk in a version 1 file"""
         f = self._repo.vfs(self.statepathv1, 'w')
         irecords = iter(records)
-        lrecords = irecords.next()
+        lrecords = next(irecords)
         assert lrecords[0] == 'L'
         f.write(hex(self._local) + '\n')
         for rtype, data in irecords:
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/peer.py
--- a/mercurial/peer.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/peer.py	Mon May 16 21:30:53 2016 +0000
@@ -98,12 +98,12 @@
     '''
     def plain(*args, **opts):
         batchable = f(*args, **opts)
-        encargsorres, encresref = batchable.next()
+        encargsorres, encresref = next(batchable)
         if not encresref:
             return encargsorres # a local result in this case
         self = args[0]
         encresref.set(self._submitone(f.func_name, encargsorres))
-        return batchable.next()
+        return next(batchable)
     setattr(plain, 'batchable', f)
     return plain
 
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/revset.py
--- a/mercurial/revset.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/revset.py	Mon May 16 21:30:53 2016 +0000
@@ -2821,9 +2821,9 @@
         # Consume both iterators in an ordered way until one is empty
         while True:
             if val1 is None:
-                val1 = iter1.next()
+                val1 = next(iter1)
             if val2 is None:
-                val2 = iter2.next()
+                val2 = next(iter2)
             n = choice(val1, val2)
             yield n
             if val1 == n:
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/tags.py
--- a/mercurial/tags.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/tags.py	Mon May 16 21:30:53 2016 +0000
@@ -292,7 +292,7 @@
     cachehash = None
     if cachefile:
         try:
-            validline = cachelines.next()
+            validline = next(cachelines)
             validline = validline.split()
             cacherev = int(validline[0])
             cachenode = bin(validline[1])
diff -r 41e57b118c22 -r bbcfd471e0c5 mercurial/wireproto.py
--- a/mercurial/wireproto.py	Mon May 16 21:30:32 2016 +0000
+++ b/mercurial/wireproto.py	Mon May 16 21:30:53 2016 +0000
@@ -97,7 +97,7 @@
             batchablefn = getattr(mtd, 'batchable', None)
             if batchablefn is not None:
                 batchable = batchablefn(mtd.im_self, *args, **opts)
-                encargsorres, encresref = batchable.next()
+                encargsorres, encresref = next(batchable)
                 if encresref:
                     req.append((name, encargsorres,))
                     rsp.append((batchable, encresref, resref,))
@@ -115,7 +115,7 @@
         for encres, r in zip(encresults, rsp):
             batchable, encresref, resref = r
             encresref.set(encres)
-            resref.set(batchable.next())
+            resref.set(next(batchable))
 
 class remoteiterbatcher(peer.iterbatcher):
     def __init__(self, remote):
@@ -138,7 +138,7 @@
         for name, args, opts, resref in self.calls:
             mtd = getattr(self._remote, name)
             batchable = mtd.batchable(mtd.im_self, *args, **opts)
-            encargsorres, encresref = batchable.next()
+            encargsorres, encresref = next(batchable)
             assert encresref
             req.append((name, encargsorres))
             rsp.append((batchable, encresref))
@@ -150,7 +150,7 @@
         for (batchable, encresref), encres in itertools.izip(
                 self._rsp, self._resultiter):
             encresref.set(encres)
-            yield batchable.next()
+            yield next(batchable)
 
 # Forward a couple of names from peer to make wireproto interactions
 # slightly more sensible.


More information about the Mercurial-devel mailing list