Skip to content
Myr

`IncludedTemplate` uses getattr rather then getitem now

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 963f97d · Browse files · 2 files+16 added−8 removed
This commit

State

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

Diff stats

2 files+16 added−8 removed

  • other:+16 added−8 removed

2 files+16 added−8 removed

modified:jinja2/compiler.py+1 added-1 removed
791 unmodified lines
792 self.write(')')793794 def visit_ExprStmt(self, node, frame):795 self.newline(node)796 self.visit(node, frame)796 self.visit(node.node, frame)797798 def visit_Output(self, node, frame):799 # if we have a known extends statement, we don't output anything800 if self.has_known_extends and frame.toplevel:
275 unmodified lines
modified:jinja2/environment.py+15 added-7 removed
13 unmodified lines
14from jinja2.optimizer import optimize15from jinja2.compiler import generate16from jinja2.runtime import Undefined, TemplateContext17from jinja2.debug import translate_exception18from jinja2.utils import import_string, LRUCache18from jinja2.utils import import_string, LRUCache, Markup19from jinja2.defaults import DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE202122# for direct template usage we have up to ten living environments
324 unmodified lines
347 return TemplateContext(self.environment, dict(self.globals, **vars),348 self.name, self.blocks)349350 def include(self, context=None):351 """Include this template."""351 """Include this template. When passed a template context or dict352 the template is evaluated in that context and an `IncludedTemplate`353 object is returned. This object then exposes all the exported354 variables as attributes and renders the contents of the template355 when converted to unicode.356 """357 if context is None:358 context = self.new_context({})359 elif isinstance(context, TemplateContext):360 context = self.new_context(context.get_root())
33 unmodified lines
394class IncludedTemplate(object):395 """Represents an included template."""396397 def __init__(self, template, context):393 self._template = template398 body = Markup(u''.join(template.root_render_func(context)))399 self.__dict__.update(context.get_exported())400 self._name = template.name395 self._rendered_body = u''.join(template.root_render_func(context))396 self._context = context.get_exported()401 self._rendered_body = body402398 __getitem__ = lambda x, n: x._context[n]399 __html__ = __unicode__ = lambda x: x._rendered_body403 __html__ = lambda x: x._rendered_body404 __unicode__ = lambda x: unicode(x._rendered_body)405406 def __str__(self):407 return unicode(self._rendered_body).encode('utf-8')408409 def __repr__(self):410 return '<%s %r>' % (411 self.__class__.__name__,412 self._name
55 unmodified lines