Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #4462 -- Use builtin reversed() function when available (in "fo…

…r" tag).

Thanks, Brian Harring.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5454 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 03ecc00f6ea756d4659b4cacab3eb6e7405e49e0 1 parent a33fb69
@malcolmt malcolmt authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/template/defaulttags.py
View
14 django/template/defaulttags.py
@@ -7,6 +7,14 @@
import sys
import re
+if not hasattr(__builtins__, 'reversed'):
+ # For Python 2.3.
+ # 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]
+
+
register = Library()
class CommentNode(Node):
@@ -103,11 +111,7 @@ def render(self, context):
values = list(values)
len_values = len(values)
if self.reversed:
- # From http://www.python.org/doc/current/tut/node11.html
- def reverse(data):
- for index in range(len(data)-1, -1, -1):
- yield data[index]
- values = reverse(values)
+ values = reversed(values)
unpack = len(self.loopvars) > 1
for i, item in enumerate(values):
context['forloop'] = {
Please sign in to comment.
Something went wrong with that request. Please try again.