diff options
| author | DasIch <dasdasich@gmail.com> | 2010-08-21 21:08:15 +0200 |
|---|---|---|
| committer | DasIch <dasdasich@gmail.com> | 2010-08-21 21:08:15 +0200 |
| commit | f883c953ca5f077c5dfc7c31217ea2bd3c2b0bcf (patch) | |
| tree | 6d7015d73e0d3d1cb31f949bed9216f3b64d1157 | |
| parent | 9ed870e653971a8176b135e601023e73f56f4d6d (diff) | |
| download | sphinx-f883c953ca5f077c5dfc7c31217ea2bd3c2b0bcf.tar.gz | |
Added a fallback for itertools.izip_longest to pycompat for python versions < 2.6
| -rw-r--r-- | sphinx/util/pycompat.py | 21 | ||||
| -rw-r--r-- | sphinx/versioning.py | 6 |
2 files changed, 22 insertions, 5 deletions
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index faebcd01..bfe96a98 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -33,6 +33,27 @@ except ImportError: # python < 2.6 for prod in result: yield tuple(prod) +try: + from itertools import izip_longest as zip_longest +except ImportError: # python > 2.6/2.7 or python < 2.6 + try: + from itertools import zip_longest + except ImportError: # python < 2.6 + # this code has been taken from the python documentation + from itertools import repeat, chain, izip + + def zip_longest(*args, **kwargs): + fillvalue = kwargs.get('fillvalue') + def sentinel(counter=([fillvalue] * (len(args) - 1)).pop): + yield counter() + fillers = repeat(fillvalue) + iters = [chain(it, sentinel(), fillers) for it in args] + try: + for tup in izip(*iters): + yield tup + except IndexError: + pass + # the ubiquitous "bytes" helper function if sys.version_info >= (3, 0): diff --git a/sphinx/versioning.py b/sphinx/versioning.py index 0ea494f0..5b0b2127 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -12,12 +12,8 @@ from uuid import uuid4 from operator import itemgetter from collections import defaultdict -try: - from itertools import izip_longest as zip_longest -except ImportError: - from itertools import zip_longest -from sphinx.util.pycompat import product +from sphinx.util.pycompat import product, zip_longest # anything below that ratio is considered equal/changed |
