summaryrefslogtreecommitdiff
path: root/django/utils/itercompat.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-12-22 15:18:51 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-12-22 15:18:51 +0000
commitff60c5f9de3e8690d1e86f3e9e3f7248a15397c8 (patch)
treea4cb0ebdd55fcaf8c8855231b6ad3e1a7bf45bee /django/utils/itercompat.py
parent7ef212af149540aa2da577a960d0d87029fd1514 (diff)
Fixed #1142 -- Added multiple database support.
This monster of a patch is the result of Alex Gaynor's 2009 Google Summer of Code project. Congratulations to Alex for a job well done. Big thanks also go to: * Justin Bronn for keeping GIS in line with the changes, * Karen Tracey and Jani Tiainen for their help testing Oracle support * Brett Hoerner, Jon Loyens, and Craig Kimmerer for their feedback. * Malcolm Treddinick for his guidance during the GSoC submission process. * Simon Willison for driving the original design process * Cal Henderson for complaining about ponies he wanted. ... and everyone else too numerous to mention that helped to bring this feature into fruition. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11952 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/itercompat.py')
-rw-r--r--django/utils/itercompat.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py
index 4a28f81d8b..639fc17e15 100644
--- a/django/utils/itercompat.py
+++ b/django/utils/itercompat.py
@@ -45,6 +45,19 @@ def groupby(iterable, keyfunc=None):
l.append(item)
yield lastkey, l
+def product(*args, **kwds):
+ """
+ Taken from http://docs.python.org/library/itertools.html#itertools.product
+ """
+ # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
+ # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
+ pools = map(tuple, args) * kwds.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)
+
# Not really in itertools, since it's a builtin in Python 2.4 and later, but it
# does operate as an iterator.
def reversed(data):
@@ -57,6 +70,8 @@ else:
tee = compat_tee
if hasattr(itertools, 'groupby'):
groupby = itertools.groupby
+if hasattr(itertools, 'product'):
+ product = itertools.product
def is_iterable(x):
"A implementation independent way of checking for iterables"
@@ -73,3 +88,8 @@ def sorted(in_value):
out_value.sort()
return out_value
+def all(iterable):
+ for item in iterable:
+ if not item:
+ return False
+ return True