py3: convert to next() function
authortimeless <timeless@mozdev.org>
Mon, 16 May 2016 21:30:53 +0000
changeset 31607 ead25aa27a438544639e01cb2f0e6ddf433ecc1a
parent 31606 f5983805574e93eb002800ea3e909992bbb5cb03
child 31608 2f9ad6ca19c27744f0afa132d857dc2bba4127aa
push id231
push usergszorc@mozilla.com
push dateThu, 26 May 2016 03:04:27 +0000
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
contrib/synthrepo.py
doc/hgmanpage.py
hgext/highlight/highlight.py
mercurial/ancestor.py
mercurial/cmdutil.py
mercurial/copies.py
mercurial/hgweb/webcommands.py
mercurial/hgweb/webutil.py
mercurial/merge.py
mercurial/peer.py
mercurial/revset.py
mercurial/tags.py
mercurial/wireproto.py
--- a/contrib/synthrepo.py
+++ b/contrib/synthrepo.py
@@ -502,15 +502,15 @@ def renamedirs(dirs, words):
         '''
         if dirpath in replacements:
             return replacements[dirpath]
         head, _ = os.path.split(dirpath)
         if head:
             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 = []
     for dirpath, count in dirs.iteritems():
         result.append([rename(dirpath.lstrip(os.sep)), count])
     return result
--- a/doc/hgmanpage.py
+++ b/doc/hgmanpage.py
@@ -788,17 +788,17 @@ class Translator(nodes.NodeVisitor):
         pass
 
     def depart_line(self, node):
         self.body.append('\n')
 
     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):
         pass
 
     def visit_literal(self, node):
         self.body.append(self.defs['literal'][0])
 
--- a/hgext/highlight/highlight.py
+++ b/hgext/highlight/highlight.py
@@ -63,13 +63,13 @@ def pygmentize(field, fctx, style, tmpl,
         return
 
     formatter = HtmlFormatter(nowrap=True, style=style)
 
     colorized = highlight(text, lexer, formatter)
     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')
     tmpl.cache[field] = newl
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -286,17 +286,17 @@ class lazyancestors(object):
         if inclusive:
             self._containsseen = set(revs)
         else:
             self._containsseen = set()
 
     def __nonzero__(self):
         """False if the set is empty, True otherwise."""
         try:
-            iter(self).next()
+            next(iter(self))
             return True
         except StopIteration:
             return False
 
     def __iter__(self):
         """Generate the ancestors of _initrevs in reverse topological order.
 
         If inclusive is False, yield a sequence of revision numbers starting
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1993,17 +1993,17 @@ def _makelogrevset(repo, pats, opts, rev
     # follow or not follow?
     follow = opts.get('follow') or opts.get('follow_first')
     if opts.get('follow_first'):
         followfirst = 1
     else:
         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
     # the same time
     opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
     opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
     # pats/include/exclude are passed to match.match() directly in
     # _matchfiles() revset but walkchangerevs() builds its matcher with
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -479,26 +479,26 @@ def checkcopies(ctx, f, m1, m2, ca, limi
         if f1 == f2:
             return f1 # a match
 
         g1, g2 = f1.ancestors(), f2.ancestors()
         try:
             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:
                     return False # copy no longer relevant
         except StopIteration:
             return False
 
     of = None
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -134,17 +134,17 @@ def _filerevision(web, req, tmpl, fctx):
         mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
         text = '(binary:%s)' % mt
 
     def lines():
         for lineno, t in enumerate(text.splitlines(True)):
             yield {"line": t,
                    "lineid": "l%d" % (lineno + 1),
                    "linenumber": "% 6d" % (lineno + 1),
-                   "parity": parity.next()}
+                   "parity": next(parity)}
 
     return tmpl("filerevision",
                 file=f,
                 path=webutil.up(f),
                 text=lines(),
                 symrev=webutil.symrevorshortnode(req, fctx),
                 rename=webutil.renamelink(fctx),
                 permissions=fctx.manifest().flags(f),
@@ -273,17 +273,17 @@ def _search(web, req, tmpl):
 
         for ctx in searchfunc[0](funcarg):
             count += 1
             n = ctx.node()
             showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
             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))
 
             if count >= revcount:
                 break
 
     query = req.form['rev'][0]
@@ -370,17 +370,17 @@ def changelog(web, req, tmpl, shortlog=F
             revs = web.repo.changelog.revs(pos, 0)
         curcount = 0
         for rev in revs:
             curcount += 1
             if curcount > revcount + 1:
                 break
 
             entry = webutil.changelistentry(web, web.repo[rev], tmpl)
-            entry['parity'] = parity.next()
+            entry['parity'] = next(parity)
             yield entry
 
     if shortlog:
         revcount = web.maxshortchanges
     else:
         revcount = web.maxchanges
 
     if 'revcount' in req.form:
@@ -522,17 +522,17 @@ def manifest(web, req, tmpl):
         raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path)
 
     def filelist(**map):
         for f in sorted(files):
             full = files[f]
 
             fctx = ctx.filectx(full)
             yield {"file": full,
-                   "parity": parity.next(),
+                   "parity": next(parity),
                    "basename": f,
                    "date": fctx.date(),
                    "size": fctx.size(),
                    "permissions": mf.flags(full)}
 
     def dirlist(**map):
         for d in sorted(dirs):
 
@@ -540,26 +540,26 @@ def manifest(web, req, tmpl):
             h = dirs[d]
             while isinstance(h, dict) and len(h) == 1:
                 k, v = h.items()[0]
                 if v:
                     emptydirs.append(k)
                 h = v
 
             path = "%s%s" % (abspath, d)
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "path": path,
                    "emptydirs": "/".join(emptydirs),
                    "basename": d}
 
     return tmpl("manifest",
                 symrev=symrev,
                 path=abspath,
                 up=webutil.up(abspath),
-                upparity=parity.next(),
+                upparity=next(parity),
                 fentries=filelist,
                 dentries=dirlist,
                 archives=web.archivelist(hex(node)),
                 **webutil.commonentry(web.repo, ctx))
 
 @webcommand('tags')
 def tags(web, req, tmpl):
     """
@@ -577,17 +577,17 @@ def tags(web, req, tmpl):
 
     def entries(notip, latestonly, **map):
         t = i
         if notip:
             t = [(k, n) for k, n in i if k != "tip"]
         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)}
 
     return tmpl("tags",
                 node=hex(web.repo.changelog.tip()),
                 entries=lambda **x: entries(False, False, **x),
                 entriesnotip=lambda **x: entries(True, False, **x),
@@ -610,17 +610,17 @@ def bookmarks(web, req, tmpl):
     i = sorted(i, key=sortkey, reverse=True)
     parity = paritygen(web.stripecount)
 
     def entries(latestonly, **map):
         t = i
         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)}
 
     if i:
         latestrev = i[0][1]
     else:
         latestrev = -1
@@ -672,44 +672,44 @@ def summary(web, req, tmpl):
             if k == "tip": # skip tip
                 continue
 
             count += 1
             if count > 10: # limit to 10 tags
                 break
 
             yield tmpl("tagentry",
-                       parity=parity.next(),
+                       parity=next(parity),
                        tag=k,
                        node=hex(n),
                        date=web.repo[n].date())
 
     def bookmarks(**map):
         parity = paritygen(web.stripecount)
         marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo]
         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)}
 
     def changelist(**map):
         parity = paritygen(web.stripecount, offset=start - end)
         l = [] # build a list in forward order for efficiency
         revs = []
         if start < end:
             revs = web.repo.changelog.revs(start, end - 1)
         for i in revs:
             ctx = web.repo[i]
 
             l.append(tmpl(
                 'shortlogentry',
-                parity=parity.next(),
+                parity=next(parity),
                 **webutil.commonentry(web.repo, ctx)))
 
         l.reverse()
         yield l
 
     tip = web.repo['tip']
     count = len(web.repo)
     start = max(0, count - web.maxchanges)
@@ -874,17 +874,17 @@ def annotate(web, req, tmpl):
             lines = enumerate(fctx.annotate(follow=True, linenumber=True,
                                             diffopts=diffopts))
         for lineno, ((f, targetline), l) in lines:
             fnode = f.filenode()
 
             if last != fnode:
                 last = fnode
 
-            yield {"parity": parity.next(),
+            yield {"parity": next(parity),
                    "node": f.hex(),
                    "rev": f.rev(),
                    "author": f.user(),
                    "desc": f.description(),
                    "extra": f.extra(),
                    "file": f.path(),
                    "targetline": targetline,
                    "line": l,
@@ -958,17 +958,17 @@ def filelog(web, req, tmpl):
         l = []
 
         repo = web.repo
         revs = fctx.filelog().revs(start, end - 1)
         for i in revs:
             iterfctx = fctx.filectx(i)
 
             l.append(dict(
-                parity=parity.next(),
+                parity=next(parity),
                 filerev=i,
                 file=f,
                 rename=webutil.renamelink(iterfctx),
                 **webutil.commonentry(repo, iterfctx)))
         for e in reversed(l):
             yield e
 
     entries = list(entries())
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -70,17 +70,17 @@ class revnav(object):
 
     def __nonzero__(self):
         """return True if any revision to navigate over"""
         return self._first() is not None
 
     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
 
     def hex(self, rev):
         return hex(self._revlog.node(rev))
 
     def gen(self, pos, pagelen, limit):
         """computes label and revision id for navigation link
@@ -242,17 +242,17 @@ def branchentries(repo, stripecount, lim
             count += 1
             if closed:
                 status = 'closed'
             elif ctx.node() not in heads:
                 status = 'inactive'
             else:
                 status = 'open'
             yield {
-                'parity': parity.next(),
+                'parity': next(parity),
                 'branch': ctx.branch(),
                 'status': status,
                 'node': ctx.hex(),
                 'date': ctx.date()
             }
 
     return entries
 
@@ -364,17 +364,17 @@ def changesetentry(web, req, tmpl, ctx):
     showbranch = nodebranchnodefault(ctx)
 
     files = []
     parity = paritygen(web.stripecount)
     for blockno, f in enumerate(ctx.files()):
         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:
         basectx = ctx.p1()
 
     style = web.config('web', 'style', 'paper')
     if 'style' in req.form:
         style = req.form['style'][0]
@@ -445,25 +445,25 @@ def diffs(repo, tmpl, ctx, basectx, file
             node1 = nullid
     else:
         node1 = basectx.node()
     node2 = ctx.node()
 
     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):
     '''Generator function that provides side-by-side comparison data.'''
 
     def compline(type, leftlineno, leftline, rightlineno, rightline):
         lineid = leftlineno and ("l%s" % leftlineno) or ''
         lineid += rightlineno and ("r%s" % rightlineno) or ''
@@ -516,39 +516,39 @@ def diffstatgen(ctx, basectx):
     stats = patch.diffstatdata(util.iterlines(ctx.diff(basectx)))
     maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
     while True:
         yield stats, maxname, maxtotal, addtotal, removetotal, binary
 
 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):
         if maxtotal == 0:
             return 0
         return (float(i) / maxtotal) * 100
 
     fileno = 0
     for filename, adds, removes, isbinary in stats:
         template = filename in files and 'diffstatlink' or 'diffstatnolink'
         total = adds + removes
         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='?'):
         self.start = start
         self.vars = vars
     def __getitem__(self, key):
         return self.vars[key]
     def __setitem__(self, key, value):
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -368,17 +368,17 @@ class mergestate(object):
         """Write current state on disk (both v1 and v2)"""
         self._writerecordsv1(records)
         self._writerecordsv2(records)
 
     def _writerecordsv1(self, records):
         """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:
             if rtype == 'F':
                 f.write('%s\n' % _droponode(data))
         f.close()
 
     def _writerecordsv2(self, records):
--- a/mercurial/peer.py
+++ b/mercurial/peer.py
@@ -93,22 +93,22 @@ def batchable(f):
 
     The decorator returns a function which wraps this coroutine as a plain
     method, but adds the original method as an attribute called "batchable",
     which is used by remotebatch to split the call into separate encoding and
     decoding phases.
     '''
     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
 
 class peerrepository(object):
 
     def batch(self):
         return localbatch(self)
 
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2816,19 +2816,19 @@ def _iterordered(ascending, iter1, iter2
         choice = min
 
     val1 = None
     val2 = None
     try:
         # 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:
                 val1 = None
             if val2 == n:
                 val2 = None
     except StopIteration:
         # Flush any remaining values and consume the other one
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -287,17 +287,17 @@ def _readtagcache(ui, repo):
     except IOError:
         cachefile = None
 
     cacherev = None
     cachenode = None
     cachehash = None
     if cachefile:
         try:
-            validline = cachelines.next()
+            validline = next(cachelines)
             validline = validline.split()
             cacherev = int(validline[0])
             cachenode = bin(validline[1])
             if len(validline) > 2:
                 cachehash = bin(validline[2])
         except Exception:
             # corruption of the cache, just recompute it.
             pass
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -92,17 +92,17 @@ class remotebatch(peer.batcher):
         self.remote = remote
     def submit(self):
         req, rsp = [], []
         for name, args, opts, resref in self.calls:
             mtd = getattr(self.remote, name)
             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,))
                 else:
                     resref.set(encargsorres)
             else:
                 if req:
                     self._submitreq(req, rsp)
@@ -110,17 +110,17 @@ class remotebatch(peer.batcher):
                 resref.set(mtd(*args, **opts))
         if req:
             self._submitreq(req, rsp)
     def _submitreq(self, req, rsp):
         encresults = self.remote._submitbatch(req)
         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):
         super(remoteiterbatcher, self).__init__()
         self._remote = remote
 
     def __getattr__(self, name):
         if not getattr(self._remote, name, False):
@@ -133,29 +133,29 @@ class remoteiterbatcher(peer.iterbatcher
 
         This is mostly valuable over http where request sizes can be
         limited, but can be used in other places as well.
         """
         req, rsp = [], []
         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))
         if req:
             self._resultiter = self._remote._submitbatch(req)
         self._rsp = rsp
 
     def results(self):
         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.
 batchable = peer.batchable
 future = peer.future
 
 # list of nodes encoding / decoding