summaryrefslogtreecommitdiff
path: root/django/utils/itercompat.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-05-04 14:00:30 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-05-04 14:00:30 +0000
commit5211f48ae3cc0d87a260dbf5c3ab8bdae664c4b6 (patch)
tree2b50ac06dd30395e53e7649d2a813927ccaeed94 /django/utils/itercompat.py
parent7202eb8e3194c6d9c52780526871018205bd0858 (diff)
Fixed #12164 -- Removed the Python 2.3 compatibility imports and workarounds. Thanks to timo and claudep for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13094 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/itercompat.py')
-rw-r--r--django/utils/itercompat.py58
1 files changed, 1 insertions, 57 deletions
diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py
index 639fc17e15..ab27c3ee01 100644
--- a/django/utils/itercompat.py
+++ b/django/utils/itercompat.py
@@ -6,45 +6,7 @@ these implementations if necessary.
import itertools
-def compat_tee(iterable):
- """
- Return two independent iterators from a single iterable.
-
- Based on http://www.python.org/doc/2.3.5/lib/itertools-example.html
- """
- # Note: Using a dictionary and a list as the default arguments here is
- # deliberate and safe in this instance.
- def gen(next, data={}, cnt=[0]):
- dpop = data.pop
- for i in itertools.count():
- if i == cnt[0]:
- item = data[i] = next()
- cnt[0] += 1
- else:
- item = dpop(i)
- yield item
- next = iter(iterable).next
- return gen(next), gen(next)
-
-def groupby(iterable, keyfunc=None):
- """
- Taken from http://docs.python.org/lib/itertools-functions.html
- """
- if keyfunc is None:
- keyfunc = lambda x:x
- iterable = iter(iterable)
- l = [iterable.next()]
- lastkey = keyfunc(l[0])
- for item in iterable:
- key = keyfunc(item)
- if key != lastkey:
- yield lastkey, l
- lastkey = key
- l = [item]
- else:
- l.append(item)
- yield lastkey, l
-
+# Fallback for Python 2.4, Python 2.5
def product(*args, **kwds):
"""
Taken from http://docs.python.org/library/itertools.html#itertools.product
@@ -58,18 +20,6 @@ def product(*args, **kwds):
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):
- for index in xrange(len(data)-1, -1, -1):
- yield data[index]
-
-if hasattr(itertools, 'tee'):
- tee = itertools.tee
-else:
- tee = compat_tee
-if hasattr(itertools, 'groupby'):
- groupby = itertools.groupby
if hasattr(itertools, 'product'):
product = itertools.product
@@ -82,12 +32,6 @@ def is_iterable(x):
else:
return True
-def sorted(in_value):
- "A naive implementation of sorted"
- out_value = in_value[:]
- out_value.sort()
- return out_value
-
def all(iterable):
for item in iterable:
if not item: