Added changelog entry for #92 and changed LoopContext.End to _last_iteration
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 24 Jan 2012 23:42:54 +0000 (00:42 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 24 Jan 2012 23:42:54 +0000 (00:42 +0100)
CHANGES
jinja2/runtime.py

diff --git a/CHANGES b/CHANGES
index a48208a3f68789bf93f328180f6d0264bcdbd456..6539c5fd021dd742e8bd66df4fff2edafad83dfc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,8 @@ Version 2.7
 - Added `urlencode` filter that automatically quotes values for
   URL safe usage with utf-8 as only supported encoding.  If applications
   want to change this encoding they can override the filter.
+- Accessing `last` on the loop context no longer causes the iterator
+  to be consumed into a list.
 
 Version 2.6
 -----------
index c70cb4e9311fdc9b8e3c30d539b6ab7dd366616d..5c39984170509b6ef56aa283874b845dac0cabbe 100644 (file)
@@ -30,6 +30,8 @@ to_string = unicode
 #: the identity function.  Useful for certain things in the environment
 identity = lambda x: x
 
+_last_iteration = object()
+
 
 def markup_join(seq):
     """Concatenation that escapes if necessary and converts to unicode."""
@@ -266,7 +268,6 @@ class BlockReference(object):
 
 class LoopContext(object):
     """A loop context for dynamic iteration."""
-    End = object()
 
     def __init__(self, iterable, recurse=None):
         self._iterator = iter(iterable)
@@ -290,7 +291,7 @@ class LoopContext(object):
         return args[self.index0 % len(args)]
 
     first = property(lambda x: x.index0 == 0)
-    last = property(lambda x: x._after is LoopContext.End)
+    last = property(lambda x: x._after is _last_iteration)
     index = property(lambda x: x.index0 + 1)
     revindex = property(lambda x: x.length - x.index0)
     revindex0 = property(lambda x: x.length - x.index)
@@ -305,7 +306,7 @@ class LoopContext(object):
         try:
             return next(self._iterator)
         except StopIteration:
-            return self.End
+            return _last_iteration
 
     @internalcode
     def loop(self, iterable):
@@ -352,8 +353,8 @@ class LoopContextIterator(object):
     def next(self):
         ctx = self.context
         ctx.index0 += 1
-        if ctx._after is LoopContext.End:
-            raise StopIteration
+        if ctx._after is _last_iteration:
+            raise StopIteration()
         next_elem = ctx._after
         ctx._after = ctx._safe_next()
         return next_elem, ctx