some more cleaning up
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 2b22874 · Browse files · 3 files·+19 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+19 added−20 removed
- other:+19 added−20 removed
Provenance
- Commit
771c750- Tree
8b611b6- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2b22874
3 files changed+19 added−20 removed
modified:jinja2/compiler.py+3 added-3 removed
640 unmodified lines641 self.indent()642 self.writeline('if parent_template is not None:')643 self.indent()644 self.writeline('for event in parent_template.'645- 'root_render_func(context):')645+ '_root_render_func(context):')646 self.indent()647 self.writeline('yield event')648 self.outdent(2 + (not self.has_known_extends))649 99 unmodified lines749 if node.with_context:750 self.writeline('template = environment.get_template(', node)751 self.visit(node.template, frame)752 self.write(', %r)' % self.name)753- self.writeline('for event in template.root_render_func('753+ self.writeline('for event in template._root_render_func('754 'template.new_context(context.parent, True)):')755 else:756 self.writeline('for event in environment.get_template(', node)757 self.visit(node.template, frame)758- self.write(', %r).module._TemplateModule__body_stream:' %758+ self.write(', %r).module._body_stream:' %759 self.name)760 self.indent()761 if frame.buffer is None:762 self.writeline('yield event')614 unmodified linesmodified:jinja2/environment.py+14 added-17 removed
462 unmodified lines463 '__jinja_template__': t464 }465 exec code in namespace466 t.environment = environment467+ t.globals = globals468 t.name = namespace['name']469 t.filename = code.co_filename469- t.root_render_func = namespace['root']470 t.blocks = namespace['blocks']471- t.globals = globals471 472+ # render function and module 473+ t._root_render_func = namespace['root']474+ t._module = None475+476 # debug and loader helpers477 t._debug_info = namespace['debug_info']478 t._uptodate = uptodate479 8 unmodified lines488 template.render({'knights': 'that say nih'})489 490 This will return the rendered template as unicode string.491 """492+ vars = dict(*args, **kwargs)493 try:490- return concat(self._generate(*args, **kwargs))494+ return concat(self._root_render_func(self.new_context(vars)))495 except:496 from jinja2.debug import translate_exception497 exc_type, exc_value, tb = translate_exception(sys.exc_info())498 raise exc_type, exc_value, tb11 unmodified lines510 a generator that yields one item after another as unicode strings.511 512 It accepts the same arguments as :meth:`render`.513 """514+ vars = dict(*args, **kwargs)515 try:511- for item in self._generate(*args, **kwargs):512- yield item516+ for event in self._root_render_func(self.new_context(vars)):517+ yield event518 except:519 from jinja2.debug import translate_exception520 exc_type, exc_value, tb = translate_exception(sys.exc_info())521 raise exc_type, exc_value, tb522 518- def _generate(self, *args, **kwargs):519- """Creates a new context and generates the template."""520- return self.root_render_func(self.new_context(dict(*args, **kwargs)))521-523 def new_context(self, vars=None, shared=False):524 """Create a new template context for this template. The vars525 provided will be passed to the template. Per default the globals526 are added to the context, if shared is set to `True` the data29 unmodified lines556 u'23'557 >>> t.module.foo()558 u'42'559 """559- if hasattr(self, '_module'):560+ if self._module is not None:561 return self._module562 self._module = rv = self.make_module()563 return rv564 33 unmodified lines598 converting it into an unicode- or bytestrings renders the contents.599 """600 601 def __init__(self, template, context):601- # don't alter this attribute unless you change it in the602- # compiler too. The Include without context passing directly603- # uses the mangled name. The reason why we use a mangled one604- # is to avoid name clashes with macros with those names.605- self.__body_stream = list(template.root_render_func(context))602+ self._body_stream = list(template._root_render_func(context))603 self.__dict__.update(context.get_exported())604 self.__name__ = template.name605 609- __html__ = lambda x: Markup(concat(x.__body_stream))610- __unicode__ = lambda x: unicode(concat(x.__body_stream))606+ __html__ = lambda x: Markup(concat(x._body_stream))607+ __unicode__ = lambda x: unicode(concat(x._body_stream))608 609 def __str__(self):610 return unicode(self).encode('utf-8')611 67 unmodified linesmodified:jinja2/runtime.py+2 added
54 unmodified lines55 `__getitem__`, `__contains__`). Additionally there is a :meth:`resolve`56 method that doesn't fail with a `KeyError` but returns an57 :class:`Undefined` object for missing variables.58 """59+ __slots__ = ('parent', 'vars', 'environment', 'exported_vars', 'name',60+ 'blocks')61 62 def __init__(self, environment, parent, name, blocks):63 self.parent = parent64 self.vars = vars = {}376 unmodified lines