mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added a fallback for itertools.izip_longest to pycompat for python versions < 2.6
This commit is contained in:
parent
043579e468
commit
bbd39e5533
@ -33,6 +33,27 @@ except ImportError: # python < 2.6
|
|||||||
for prod in result:
|
for prod in result:
|
||||||
yield tuple(prod)
|
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
|
# the ubiquitous "bytes" helper function
|
||||||
if sys.version_info >= (3, 0):
|
if sys.version_info >= (3, 0):
|
||||||
|
@ -12,12 +12,8 @@
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from collections import defaultdict
|
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
|
# anything below that ratio is considered equal/changed
|
||||||
|
Loading…
Reference in New Issue
Block a user