Added a fallback for itertools product to pycompat for python versions < 2.6

This commit is contained in:
Daniel Neuhäuser 2010-08-21 20:53:05 +02:00
parent aa9fabc1e1
commit 043579e468
2 changed files with 14 additions and 1 deletions

View File

@ -21,6 +21,18 @@ except ImportError:
# Python 3
class_types = (type,)
try:
from itertools import product
except ImportError: # python < 2.6
# this code has been taken from the python documentation
def product(*args, **kwargs):
pools = map(tuple, args) * kwargs.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x + [y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
# the ubiquitous "bytes" helper function
if sys.version_info >= (3, 0):

View File

@ -12,12 +12,13 @@
from uuid import uuid4
from operator import itemgetter
from collections import defaultdict
from itertools import product
try:
from itertools import izip_longest as zip_longest
except ImportError:
from itertools import zip_longest
from sphinx.util.pycompat import product
# anything below that ratio is considered equal/changed
VERSIONING_RATIO = 65