summaryrefslogtreecommitdiff
path: root/sphinx/util/pycompat.py
diff options
context:
space:
mode:
authorDasIch <dasdasich@gmail.com>2010-08-21 21:08:15 +0200
committerDasIch <dasdasich@gmail.com>2010-08-21 21:08:15 +0200
commitf883c953ca5f077c5dfc7c31217ea2bd3c2b0bcf (patch)
tree6d7015d73e0d3d1cb31f949bed9216f3b64d1157 /sphinx/util/pycompat.py
parent9ed870e653971a8176b135e601023e73f56f4d6d (diff)
downloadsphinx-f883c953ca5f077c5dfc7c31217ea2bd3c2b0bcf.tar.gz
Added a fallback for itertools.izip_longest to pycompat for python versions < 2.6
Diffstat (limited to 'sphinx/util/pycompat.py')
-rw-r--r--sphinx/util/pycompat.py21
1 files changed, 21 insertions, 0 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):