[svn] removed debug print, small changes in context
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 28 Feb 2007 21:39:44 +0000 (22:39 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 28 Feb 2007 21:39:44 +0000 (22:39 +0100)
--HG--
branch : trunk

jinja/datastructure.py
jinja/translators/python.py
tests/bigtable.py

index 67a4b89f6ce533dd1d447bf991caddc7f3445c4e..96bce49efe5dae770ccaaf98d2d0db8275dc5b0d 100644 (file)
@@ -82,16 +82,9 @@ class Context(object):
     Dict like object.
     """
 
-    def __init__(*args, **kwargs):
-        try:
-            self = args[0]
-            self.environment = args[1]
-            initial = dict(*args[2:], **kwargs)
-        except:
-            raise TypeError('%r requires environment as first argument. '
-                            'The rest of the arguments are forwarded to '
-                            'the default dict constructor.')
-        self._stack = [self.environment.globals, initial, {}]
+    def __init__(self, _environment_, *args, **kwargs):
+        self.environment = _environment_
+        self._stack = [self.environment.globals, dict(*args, **kwargs), {}]
         self.globals, _, self.current = self._stack
 
     def pop(self):
@@ -181,6 +174,9 @@ class LoopContext(object):
             s['index'] = idx
             yield item
 
+    def __len__(self):
+        return self._stack[-1]['length']
+
     def __call__(self, seq):
         if self.loop_function is not None:
             return self.loop_function(seq)
index 92ef61edf51a6eb31db67b01f325e649b32b3396..a8e3fdee2c3b61e5abcdb14e27011999be096404 100644 (file)
@@ -115,7 +115,6 @@ class PythonTranslator(Translator):
     def process(environment, node):
         translator = PythonTranslator(environment, node)
         source = translator.translate()
-        print source
         ns = {}
         exec source in ns
         return Template(environment, ns['generate'])
index 01c188b2dc10560289bcd2027f3de008e7d94bdf..ff9e1ee6494ac7d1c17c2499f8bca17a23f7b9cd 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*_
 # Template language benchmarks
 #
 # Objective: Generate a 1000x10 HTML table as fast as possible.