Skip to content
Myr

fixed a bug in extension handling

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 d1ff858 · Browse files · 6 files+58 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+58 added−7 removed

  • other:+58 added−7 removed

6 files+58 added−7 removed

modified:docs/cache_extension.py+2 added-4 removed
36 unmodified lines
37 body = parser.parse_statements(['name:endcache'], drop_needle=True)3839 # now return a `CallBlock` node that calls our _cache_support40 # helper method on this extension.41 return nodes.CallBlock(42 nodes.Call(self.attr('_cache_support'), args, [], None, None),43 [], [], body44 ).set_lineno(lineno)41 return nodes.CallBlock(self.call_method('_cache_support', args),42 [], [], body).set_lineno(lineno)4344 def _cache_support(self, name, timeout, caller):45 """Helper callback."""46 key = self.environment.fragment_cache_prefix + name
10 unmodified lines
modified:docs/extensions.rst+1 added-1 removed
132 unmodified lines
133134Extensions always have to extend the :class:`jinja2.ext.Extension` class:135136.. autoclass:: Extension137 :members: parse, attr137 :members: parse, attr, call_method138139 .. attribute:: identifier140141 The identifier of the extension. This is always the true import name
70 unmodified lines
modified:jinja2/compiler.py+2 added-1 removed
717 unmodified lines
718719 # if this extends statement was in the root level we can take720 # advantage of that information and simplify the generated code721 # in the top level from this point onwards722 if frame.rootlevel:722 self.has_known_extends = True723 self.has_known_extends = True724725 # and now we have one more726 self.extends_so_far += 1727
554 unmodified lines
modified:jinja2/environment.py+3 added-1 removed
13 unmodified lines
14from jinja2.parser import Parser15from jinja2.optimizer import optimize16from jinja2.compiler import generate17from jinja2.runtime import Undefined, Context18from jinja2.debug import translate_exception, translate_syntax_error18from jinja2.exceptions import TemplateSyntaxError19from jinja2.utils import import_string, LRUCache, Markup, missing, concat2021
275 unmodified lines
297 """298 try:299 return Parser(self, source, filename).parse()300 except TemplateSyntaxError, e:301 from jinja2.debug import translate_syntax_error302 exc_type, exc_value, tb = translate_syntax_error(e)303 raise exc_type, exc_value, tb304305 def lex(self, source, filename=None):
179 unmodified lines
485 """486 try:487 return concat(self._generate(*args, **kwargs))488 except:489 from jinja2.debug import translate_exception490 exc_type, exc_value, tb = translate_exception(sys.exc_info())491 raise exc_type, exc_value, tb492493 def stream(self, *args, **kwargs):
13 unmodified lines
507 try:508 for item in self._generate(*args, **kwargs):509 yield item510 except:511 from jinja2.debug import translate_exception512 exc_type, exc_value, tb = translate_exception(sys.exc_info())513 raise exc_type, exc_value, tb514515 def _generate(self, *args, **kwargs):
177 unmodified lines
modified:jinja2/ext.py+11 added
71 unmodified lines
72 parser as first argument. The token the parser stream is pointing at73 is the name token that matched. This method has to return one or a74 list of multiple nodes.75 """76 raise NotImplementedError()7778 def attr(self, name, lineno=None):79 """Return an attribute node for the current extension. This is useful80 to pass callbacks to template code::
3 unmodified lines
84 That would call `self._my_callback` when the template is evaluated.85 """86 return nodes.ExtensionAttribute(self.identifier, name, lineno=lineno)8788 def call_method(self, name, args=None, kwargs=None, dyn_args=None,89 dyn_kwargs=None, lineno=None):90 """Call a method of the extension."""91 if args is None:92 args = []93 if kwargs is None:94 kwargs = []95 return nodes.Call(self.attr(name, lineno=lineno), args, kwargs,96 dyn_args, dyn_kwargs, lineno=lineno)979899class InternationalizationExtension(Extension):100 """This extension adds gettext support to Jinja2."""101 tags = set(['trans'])102
261 unmodified lines
added:jinja2-debug.py+39 added
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4 Jinja2 Debug Interface5 ~~~~~~~~~~~~~~~~~~~~~~67 Helper script for internal Jinja2 debugging. Requires Werkzeug.89 :copyright: Copyright 2008 by Armin Ronacher.10 :license: BSD.11"""12import sys13import jinja214from werkzeug import script1516env = jinja2.Environment()1718def shell_init_func():19 def _compile(x):20 print env.compile(x, raw=True)21 result = {22 'e': env,23 'c': _compile,24 't': env.from_string,25 'p': env.parse26 }27 for key in jinja2.__all__:28 result[key] = getattr(jinja2, key)29 return result303132def action_compile():33 print env.compile(sys.stdin.read(), raw=True)3435action_shell = script.make_shell(shell_init_func)363738if __name__ == '__main__':39 script.run()