Ticket #4462: use-builtin-reverse-if-available.patch

File use-builtin-reverse-if-available.patch, 1.0 KB (added by (removed), 17 years ago)
  • django/template/defaulttags.py

    === modified file 'django/template/defaulttags.py'
     
    66from django.conf import settings
    77import sys
    88
     9if not hasattr(__builtins__, 'reversed'):
     10    # From http://www.python.org/doc/current/tut/node11.html
     11    def reversed(data):
     12        for index in xrange(len(data)-1, -1, -1):
     13            yield data[index]
     14
     15
    916register = Library()
    1017
    1118class CommentNode(Node):
     
    102109            values = list(values)
    103110        len_values = len(values)
    104111        if self.reversed:
    105             # From http://www.python.org/doc/current/tut/node11.html
    106             def reverse(data):
    107                 for index in range(len(data)-1, -1, -1):
    108                     yield data[index]
    109             values = reverse(values)
     112            values = reversed(values)
    110113        for i, item in enumerate(values):
    111114            context['forloop'] = {
    112115                # shortcuts for current loop iteration number
Back to Top