[svn] some small jinja changes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent a690146 · Browse files · 5 files·+16 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+16 added−26 removed
- tests:+10 added−9 removed
- other:+6 added−17 removed
Provenance
- Commit
5adf94f- Tree
31defcf- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
a690146
5 files changed+16 added−26 removed
modified:jinja/datastructure.py+1 added-2 removed
174 unmodified lines175 result[key] = value176 return result177 178 def __getitem__(self, name):179- # don't give access to jinja internal variables179 if name.startswith('::'):180 return Undefined181 # because the stack is usually quite small we better use [::-1]182 # which is faster than reversed() somehow.183 for d in self._stack[::-1]:184 if name in d:185 rv = d[name]187- if isinstance(rv, Deferred):186+ if rv.__class__ is Deferred:187 rv = rv(self, name)188 # never touch the globals!189 if d is self.globals:190 self.initial[name] = rv211 unmodified linesmodified:jinja/environment.py-1 removed
205 unmodified lines206 """207 if value is Undefined or value is None:208 return u''209 val = self.to_unicode(value)210- # apply default filters210 if self.default_filters:211 val = self.apply_filters(val, ctx, self.default_filters)212 return valmodified:jinja/nodes.py+2 added-3 removed
7 unmodified lines8 :copyright: 2007 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 from compiler import ast12+from copy import copy13 14 15 def inc_lineno(offset, tree):16 """259 unmodified lines276 def clone(self):277 """278 Create an independent clone of this node.279 """279- rv = Block(None, None, None)280- rv.__dict__.update(self.__dict__)281- return rv280+ return copy(self)281 282 def get_items(self):283 return [self.name, self.body]284 65 unmodified linesmodified:jinja/utils.py+3 added-11 removed
149 unmodified lines150 return range(start, stop, step)151 152 153 # python2.4 and lower has a bug regarding joining of broken generators154-if sys.hexversion < (2, 5):155- def capture_generator(gen):156- """157- Concatenate the generator output.158- """159- return u''.join(tuple(gen))154+if sys.version_info < (2, 5):155+ capture_generator = lambda gen: u''.join(tuple(gen))156 157 # this should be faster and used in python2.5 and higher158 else:163- def capture_generator(gen):164- """165- Concatenate the generator output166- """167- return u''.join(gen)159+ capture_generator = u''.join160 161 162 def buffereater(f):163 """249 unmodified linesmodified:tests/runtime/bigtable.py+10 added-9 removed
8 unmodified lines9 10 import cgi11 import sys12 import timeit13+import jdebug14 from StringIO import StringIO15 16 from genshi.builder import tag17 from genshi.template import MarkupTemplate31 unmodified lines49 if have_django:50 django_tmpl = DjangoTemplate("""51 <table>52 {% for row in table %}52-<tr>{% for col in row.values %}{{ col|escape }}{% endfor %}</tr>53+<tr>{% for col in row.values %}{{ col }}{% endfor %}</tr>54 {% endfor %}55 </table>56 """)57 58 jinja_tmpl = Environment().from_string('''59 <table>59-{% for row in table %}60-<tr>{% for col in row.values() %}{{ col|escape }}{% endfor %}</tr>60+{% for row in table -%}61+<tr>{% for col in row.values() %}{{ col }}{% endfor %}</tr>62 {% endfor %}63 </table>64 ''')65 66 cheetah_tmpl = CheetahTemplate('''66-# filter escape67 <table>68 #for $row in $table69 <tr>70 #for $col in $row.values()9 unmodified lines80 <table>81 % for row in table:82 <tr>83 % for col in row.values():84- ${col|h}84+ ${col}85 % endfor86 </tr>87 % endfor88 </table>47 unmodified lines136 if __name__ == '__main__':137 which = [arg for arg in sys.argv[1:] if arg[0] != '-']138 139 if '-p' in sys.argv:140- import hotshot, hotshot.stats141- prof = hotshot.Profile("template.prof")142- benchtime = prof.runcall(run, which, number=1)143- stats = hotshot.stats.load("template.prof")140+ from cProfile import Profile141+ from pstats import Stats142+ p = Profile()143+ p.runcall(test_jinja)144+ stats = Stats(p)145 stats.strip_dirs()146 stats.sort_stats('time', 'calls')147 stats.print_stats()148 else:1 unmodified line