]> arthur.barton.de Git - bup.git/commitdiff
Use next(it), not it.next() and drop the helpers fallback
authorRob Browning <rlb@defaultvalue.org>
Sun, 10 Sep 2017 20:08:33 +0000 (15:08 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 10 Sep 2017 20:08:33 +0000 (15:08 -0500)
Change all it.next() invocations to next(it) for compatibility with
newer versions of python that do not support the next() method.  Drop
the next() fallback helper since we depend on python 2.6 now.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/index-cmd.py
cmd/memtest-cmd.py
cmd/midx-cmd.py
lib/bup/gc.py
lib/bup/git.py
lib/bup/helpers.py
lib/bup/t/tgit.py
lib/bup/t/thelpers.py
lib/bup/vfs.py

index bb21b4ec23e5fd8e8b3ef67485575f36bd29e92a..2426f1f5ac8b54fee6e3f6c164c8e6f87a38a0f1 100755 (executable)
@@ -21,10 +21,7 @@ class IterHelper:
         self.next()
 
     def next(self):
-        try:
-            self.cur = self.i.next()
-        except StopIteration:
-            self.cur = None
+        self.cur = next(self.i, None)
         return self.cur
 
 
index c4c531e22928c5c95cf03f6d75adaa3a7edd1c96..fb7a1205ed17e55c05d0e0824797b0ff9518243b 100755 (executable)
@@ -100,7 +100,7 @@ if opt.existing:
 for c in xrange(opt.cycles):
     for n in xrange(opt.number):
         if opt.existing:
-            bin = objit.next()
+            bin = next(objit)
             assert(m.exists(bin))
         else:
             bin = _helpers.random_sha()
index 8e0b87e1d948bf836b58c2b8d65e57122c00dda1..0224ab40238f3239c937d5b53f67e85a4802fa02 100755 (executable)
@@ -153,7 +153,7 @@ def _do_midx(outdir, outfilename, infilenames, prefixstr):
         print p.idxnames
         assert(len(p) == total)
         for pe, e in p, git.idxmerge(inp, final_progress=False):
-            pin = pi.next()
+            pin = next(pi)
             assert(i == pin)
             assert(p.exists(i))
 
index 395094a29694dba91516f131748e549cb20cc573..6ee631fba8ace74f913b9687ec45b0f1e16445a1 100644 (file)
@@ -186,7 +186,7 @@ def sweep(live_objects, existing_count, cat_pipe, threshold, compression,
             sha = idx.shatable[i * 20 : (i + 1) * 20]
             if live_objects.exists(sha):
                 item_it = cat_pipe.get(sha.encode('hex'))
-                type = item_it.next()
+                type = next(item_it)
                 writer.just_write(sha, type, ''.join(item_it))
 
         ns.stale_files.append(idx_name)
index 826c6e5f59d4d698d7a1e21fe967edcdbeff6322..c632631c03edf2f504defba023b6704287d14eb7 100644 (file)
@@ -111,7 +111,7 @@ def parse_commit(content):
 
 def get_commit_items(id, cp):
     commit_it = cp.get(id)
-    assert(commit_it.next() == 'commit')
+    assert(next(commit_it) == 'commit')
     commit_content = ''.join(commit_it)
     return parse_commit(commit_content)
 
@@ -1105,7 +1105,7 @@ class _AbortableIter:
 
     def next(self):
         try:
-            return self.it.next()
+            return next(self.it)
         except StopIteration as e:
             self.done = True
             raise
@@ -1204,7 +1204,7 @@ class CatPipe:
             raise
 
     def _join(self, it):
-        type = it.next()
+        type = next(it)
         if type == 'blob':
             for blob in it:
                 yield blob
@@ -1303,7 +1303,7 @@ def walk_object(cat_pipe, id,
             continue
 
         item_it = cat_pipe.get(id)
-        type = item_it.next()
+        type = next(item_it)
         if type not in ('blob', 'commit', 'tree'):
             raise Exception('unexpected repository object type %r' % type)
 
index 86ac90f5793d2d38ba1a5d84c1460376e022781c..f980be2ecfd78007a8152576097018f157121014 100644 (file)
@@ -188,25 +188,6 @@ def mkdirp(d, mode=None):
             raise
 
 
-_unspecified_next_default = object()
-
-def _fallback_next(it, default=_unspecified_next_default):
-    """Retrieve the next item from the iterator by calling its
-    next() method. If default is given, it is returned if the
-    iterator is exhausted, otherwise StopIteration is raised."""
-
-    if default is _unspecified_next_default:
-        return it.next()
-    else:
-        try:
-            return it.next()
-        except StopIteration:
-            return default
-
-if sys.version_info < (2, 6):
-    next =  _fallback_next
-
-
 def merge_iter(iters, pfreq, pfunc, pfinal, key=None):
     if key:
         samekey = lambda e, pe: getattr(e, key) == getattr(pe, key, None)
@@ -229,7 +210,7 @@ def merge_iter(iters, pfreq, pfunc, pfinal, key=None):
             yield e
         count += 1
         try:
-            e = it.next() # Don't use next() function, it's too expensive
+            e = next(it)
         except StopIteration:
             heapq.heappop(heap) # remove current
         else:
@@ -623,7 +604,7 @@ class DemuxConn(BaseConn):
                 if not self._next_packet(timeout):
                     return False
             try:
-                self.buf = self.reader.next()
+                self.buf = next(self.reader)
                 return True
             except StopIteration:
                 self.reader = None
index cacec6b05157cf45cded4228b58acbde324f95fa..c330f66453c7313e21705435b6d4346677d92d82 100644 (file)
@@ -116,7 +116,7 @@ def testpacks():
 
             pi = iter(r)
             for h in sorted(hashes):
-                WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex'))
+                WVPASSEQ(str(next(pi)).encode('hex'), h.encode('hex'))
 
             WVFAIL(r.find_offset('\0'*20))
 
@@ -437,8 +437,8 @@ def test_cat_pipe():
             git_size = int(exo('git', '--git-dir', bupdir,
                                'cat-file', '-s', 'src'))
             it = git.cp().get('src', size=True)
-            get_type, get_size = it.next()
-            for buf in it.next():
+            get_type, get_size = next(it)
+            for buf in next(it):
                 pass
             WVPASSEQ(get_type, git_type)
             WVPASSEQ(get_size, git_size)
index d7d302d074f3fb2ac5dc146c22fc6f58765de4c4..c707839fdb956ce7a6dfdb50ff27510479fbd53e 100644 (file)
@@ -14,34 +14,6 @@ import bup._helpers as _helpers
 bup_tmp = os.path.realpath('../../../t/tmp')
 mkdirp(bup_tmp)
 
-@wvtest
-def test_next():
-    with no_lingering_errors():
-        # Test whatever you end up with for next() after import '*'.
-        WVPASSEQ(next(iter([]), None), None)
-        x = iter([1])
-        WVPASSEQ(next(x, None), 1)
-        WVPASSEQ(next(x, None), None)
-        x = iter([1])
-        WVPASSEQ(next(x, 'x'), 1)
-        WVPASSEQ(next(x, 'x'), 'x')
-        WVEXCEPT(StopIteration, next, iter([]))
-        x = iter([1])
-        WVPASSEQ(next(x), 1)
-        WVEXCEPT(StopIteration, next, x)
-
-
-@wvtest
-def test_fallback_next():
-    with no_lingering_errors():
-        global next
-        orig = next
-        next = helpers._fallback_next
-        try:
-            test_next()
-        finally:
-            next = orig
-
 
 @wvtest
 def test_parse_num():
index b8ebb48d102a2be3077a899c295c021d5912477a..6110a094b43d7e9cf1e63bbf8fb7996ac6de88c1 100644 (file)
@@ -37,7 +37,7 @@ class TooManySymlinks(NodeError):
 
 def _treeget(hash, repo_dir=None):
     it = cp(repo_dir).get(hash.encode('hex'))
-    type = it.next()
+    type = next(it)
     assert(type == 'tree')
     return git.tree_decode(''.join(it))
 
@@ -108,7 +108,7 @@ class _ChunkReader:
         while len(out) < size:
             if self.it and not self.blob:
                 try:
-                    self.blob = self.it.next()
+                    self.blob = next(self.it)
                 except StopIteration:
                     self.it = None
             if self.blob:
@@ -424,11 +424,11 @@ class Dir(Node):
     def _mksubs(self):
         self._subs = {}
         it = cp(self._repo_dir).get(self.hash.encode('hex'))
-        type = it.next()
+        type = next(it)
         if type == 'commit':
             del it
             it = cp(self._repo_dir).get(self.hash.encode('hex') + ':')
-            type = it.next()
+            type = next(it)
         assert(type == 'tree')
         for (mode,mangled_name,sha) in git.tree_decode(''.join(it)):
             if mangled_name == '.bupm':