X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=lib%2Fbup%2Fhelpers.py;h=ef4be682f0152d26c372ca1a8078619a30a5ab49;hb=c02dfa3dc02ff4a389237546d0f4d4c245f24356;hp=4943d70ccc6c748a157c871757848e99a478ac01;hpb=31574fc6213e219436b3c920ad27e3487e6b1430;p=bup.git diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 4943d70..ef4be68 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -126,6 +126,25 @@ 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)