From 5adf94fdc0f10e207ddbf2479c55f642c37fe40e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 29 Mar 2007 22:11:59 +0200 Subject: [PATCH] [svn] some small jinja changes --HG-- branch : trunk --- jinja/datastructure.py | 3 +-- jinja/environment.py | 1 - jinja/nodes.py | 5 ++--- jinja/utils.py | 14 +++----------- tests/runtime/bigtable.py | 19 ++++++++++--------- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/jinja/datastructure.py b/jinja/datastructure.py index e64f687..732a938 100644 --- a/jinja/datastructure.py +++ b/jinja/datastructure.py @@ -176,7 +176,6 @@ class Context(object): return result def __getitem__(self, name): - # don't give access to jinja internal variables if name.startswith('::'): return Undefined # because the stack is usually quite small we better use [::-1] @@ -184,7 +183,7 @@ class Context(object): for d in self._stack[::-1]: if name in d: rv = d[name] - if isinstance(rv, Deferred): + if rv.__class__ is Deferred: rv = rv(self, name) # never touch the globals! if d is self.globals: diff --git a/jinja/environment.py b/jinja/environment.py index f807576..329ad81 100644 --- a/jinja/environment.py +++ b/jinja/environment.py @@ -207,7 +207,6 @@ class Environment(object): if value is Undefined or value is None: return u'' val = self.to_unicode(value) - # apply default filters if self.default_filters: val = self.apply_filters(val, ctx, self.default_filters) return val diff --git a/jinja/nodes.py b/jinja/nodes.py index b9d3051..85a92b4 100644 --- a/jinja/nodes.py +++ b/jinja/nodes.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for more details. """ from compiler import ast +from copy import copy def inc_lineno(offset, tree): @@ -276,9 +277,7 @@ class Block(Node): """ Create an independent clone of this node. """ - rv = Block(None, None, None) - rv.__dict__.update(self.__dict__) - return rv + return copy(self) def get_items(self): return [self.name, self.body] diff --git a/jinja/utils.py b/jinja/utils.py index e689320..e9f6318 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -151,20 +151,12 @@ def safe_range(start, stop=None, step=None): # python2.4 and lower has a bug regarding joining of broken generators -if sys.hexversion < (2, 5): - def capture_generator(gen): - """ - Concatenate the generator output. - """ - return u''.join(tuple(gen)) +if sys.version_info < (2, 5): + capture_generator = lambda gen: u''.join(tuple(gen)) # this should be faster and used in python2.5 and higher else: - def capture_generator(gen): - """ - Concatenate the generator output - """ - return u''.join(gen) + capture_generator = u''.join def buffereater(f): diff --git a/tests/runtime/bigtable.py b/tests/runtime/bigtable.py index 9ea794d..a7deaff 100644 --- a/tests/runtime/bigtable.py +++ b/tests/runtime/bigtable.py @@ -10,6 +10,7 @@ import cgi import sys import timeit +import jdebug from StringIO import StringIO from genshi.builder import tag @@ -49,21 +50,20 @@ if have_django: django_tmpl = DjangoTemplate(""" {% for row in table %} -{% for col in row.values %}{{ col|escape }}{% endfor %} +{% for col in row.values %}{{ col }}{% endfor %} {% endfor %}
""") jinja_tmpl = Environment().from_string(''' -{% for row in table %} -{% for col in row.values() %}{{ col|escape }}{% endfor %} +{% for row in table -%} +{% for col in row.values() %}{{ col }}{% endfor %} {% endfor %}
''') cheetah_tmpl = CheetahTemplate(''' -# filter escape #for $row in $table @@ -81,7 +81,7 @@ if have_mako: % for row in table: % for col in row.values(): - ${col|h} + ${col} % endfor % endfor @@ -137,10 +137,11 @@ if __name__ == '__main__': which = [arg for arg in sys.argv[1:] if arg[0] != '-'] if '-p' in sys.argv: - import hotshot, hotshot.stats - prof = hotshot.Profile("template.prof") - benchtime = prof.runcall(run, which, number=1) - stats = hotshot.stats.load("template.prof") + from cProfile import Profile + from pstats import Stats + p = Profile() + p.runcall(test_jinja) + stats = Stats(p) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats() -- 2.26.2