From fc20eeec47f1bf7b178a0432fa74f54a452b62ce Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 23 Jun 2007 06:02:17 +0000 Subject: [PATCH] Fixed a Python 2.3 incompatibility I overlooked in [5516]. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5517 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/urlresolvers.py | 5 +++++ django/template/defaulttags.py | 7 +------ django/utils/itercompat.py | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 22604cf96d9..669b2d1afa7 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -12,6 +12,11 @@ from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.utils.functional import memoize import re +try: + reversed +except NameError: + from django.utils.itercompat import reversed # Python 2.3 fallback + _resolver_cache = {} # Maps urlconf modules to RegexURLResolver instances. _callable_cache = {} # Maps view and url pattern names to their view functions. diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 66443fc3b38..19beb29141c 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -11,12 +11,7 @@ import re try: reversed except NameError: - # Python 2.3 fallback. - # From http://www.python.org/doc/current/tut/node11.html - def reversed(data): - for index in xrange(len(data)-1, -1, -1): - yield data[index] - + from django.utils.itercompat import reversed # Python 2.3 fallback register = Library() diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py index 48a2d99d3af..ff814bfd7b1 100644 --- a/django/utils/itercompat.py +++ b/django/utils/itercompat.py @@ -45,6 +45,12 @@ def groupby(iterable, keyfunc=None): l.append(item) yield lastkey, l +# 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: