]> arthur.barton.de Git - bup.git/commitdiff
Drop helpers.next() and just use Python's built-in.
authorAidan Hobson Sayers <aidanhs@cantab.net>
Thu, 12 Dec 2013 20:29:22 +0000 (20:29 +0000)
committerRob Browning <rlb@defaultvalue.org>
Thu, 8 May 2014 17:45:47 +0000 (12:45 -0500)
The python built-in 'next' function has an optional second parameter
that specifies what to return instead of excepting with StopIteration.
There is therefore no need for the function in helpers.py.

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
[rlb@defaultvalue.org: adjust commit message.]
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
cmd/split-cmd.py
lib/bup/helpers.py

index 5ae3c0d991ab8bc322752c8d8a4dc757ba2e1d50..70daf7c688258b7da31c34a2bac83015c3316fac 100755 (executable)
@@ -108,7 +108,7 @@ if opt.git_ids:
         def __init__(self, it):
             self.it = iter(it)
         def read(self, size):
-            v = next(self.it)
+            v = next(self.it, None)
             return v or ''
     def read_ids():
         while 1:
@@ -119,7 +119,7 @@ if opt.git_ids:
                 line = line.strip()
             try:
                 it = cp.get(line.strip())
-                next(it)  # skip the file type
+                next(it, None)  # skip the file type
             except KeyError, e:
                 add_error('error: %s' % e)
                 continue
index 7d03e262d9d85de3e464dfce8fc2bf6daac1284a..4943d70ccc6c748a157c871757848e99a478ac01 100644 (file)
@@ -126,14 +126,6 @@ def mkdirp(d, mode=None):
             raise
 
 
-def next(it):
-    """Get the next item from an iterator, None if we reached the end."""
-    try:
-        return it.next()
-    except StopIteration:
-        return None
-
-
 def merge_iter(iters, pfreq, pfunc, pfinal, key=None):
     if key:
         samekey = lambda e, pe: getattr(e, key) == getattr(pe, key, None)
@@ -142,7 +134,7 @@ def merge_iter(iters, pfreq, pfunc, pfinal, key=None):
     count = 0
     total = sum(len(it) for it in iters)
     iters = (iter(it) for it in iters)
-    heap = ((next(it),it) for it in iters)
+    heap = ((next(it, None),it) for it in iters)
     heap = [(e,it) for e,it in heap if e]
 
     heapq.heapify(heap)