Renamed 'reversed' variable to 'is_reversed' in ForLoop template tag implementation, to avoid potential conflicts with the 'reversed' built-in and to make the code more obvious

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-12-22 19:38:48 +00:00
parent abffdf5940
commit e7b338d10e
1 changed files with 8 additions and 11 deletions

View File

@ -84,19 +84,16 @@ class FirstOfNode(Node):
return u''
class ForNode(Node):
def __init__(self, loopvars, sequence, reversed, nodelist_loop):
def __init__(self, loopvars, sequence, is_reversed, nodelist_loop):
self.loopvars, self.sequence = loopvars, sequence
self.reversed = reversed
self.is_reversed = is_reversed
self.nodelist_loop = nodelist_loop
def __repr__(self):
if self.reversed:
reversed = ' reversed'
else:
reversed = ''
reversed_text = self.is_reversed and ' reversed' or ''
return "<For Node: for %s in %s, tail_len: %d%s>" % \
(', '.join(self.loopvars), self.sequence, len(self.nodelist_loop),
reversed)
reversed_text)
def __iter__(self):
for node in self.nodelist_loop:
@ -125,7 +122,7 @@ class ForNode(Node):
if not hasattr(values, '__len__'):
values = list(values)
len_values = len(values)
if self.reversed:
if self.is_reversed:
values = reversed(values)
unpack = len(self.loopvars) > 1
for i, item in enumerate(values):
@ -619,8 +616,8 @@ def do_for(parser, token):
raise TemplateSyntaxError("'for' statements should have at least four"
" words: %s" % token.contents)
reversed = bits[-1] == 'reversed'
in_index = reversed and -3 or -2
is_reversed = bits[-1] == 'reversed'
in_index = is_reversed and -3 or -2
if bits[in_index] != 'in':
raise TemplateSyntaxError("'for' statements should use the format"
" 'for x in y': %s" % token.contents)
@ -634,7 +631,7 @@ def do_for(parser, token):
sequence = parser.compile_filter(bits[in_index+1])
nodelist_loop = parser.parse(('endfor',))
parser.delete_first_token()
return ForNode(loopvars, sequence, reversed, nodelist_loop)
return ForNode(loopvars, sequence, is_reversed, nodelist_loop)
do_for = register.tag("for", do_for)
def do_ifequal(parser, token, negate):