From ed03db5208ffc2d3f92cfd83d5561e025bb97add Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 28 Feb 2007 22:39:44 +0100 Subject: [PATCH] [svn] removed debug print, small changes in context --HG-- branch : trunk --- jinja/datastructure.py | 16 ++++++---------- jinja/translators/python.py | 1 - tests/bigtable.py | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jinja/datastructure.py b/jinja/datastructure.py index 67a4b89..96bce49 100644 --- a/jinja/datastructure.py +++ b/jinja/datastructure.py @@ -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) diff --git a/jinja/translators/python.py b/jinja/translators/python.py index 92ef61e..a8e3fde 100644 --- a/jinja/translators/python.py +++ b/jinja/translators/python.py @@ -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']) diff --git a/tests/bigtable.py b/tests/bigtable.py index 01c188b..ff9e1ee 100644 --- a/tests/bigtable.py +++ b/tests/bigtable.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*_ # Template language benchmarks # # Objective: Generate a 1000x10 HTML table as fast as possible. -- 2.26.2