Skip to content
Myr

Added hooks for compilation and generation. This fixes #384

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 1120b7b · Browse files · 1 file+20 added−4 removed
This commit

State

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

Diff stats

1 file+20 added−4 removed

  • other:+20 added−4 removed

1 file+20 added−4 removed

modified:jinja2/environment.py+20 added-4 removed
431 unmodified lines
432 if not isinstance(stream, TokenStream):433 stream = TokenStream(stream, name, filename)434 return stream435436 def _generate(self, source, name, filename, defer_init=False):437 """Internal hook that can be overriden to hook a different generate438 method in.439440 .. versionadded:: 2.5441 """442 return generate(source, self, name, filename, defer_init=defer_init)443444 def _compile(self, source, filename):445 """Internal hook that can be overriden to hook a different compile446 method in.447448 .. versionadded:: 2.5449 """450 return compile(source, filename, 'exec')451452 @internalcode453 def compile(self, source, name=None, filename=None, raw=False,454 defer_init=False):455 """Compile a node or template source code. The `name` parameter is
21 unmodified lines
477 source_hint = source478 source = self._parse(source, name, filename)479 if self.optimized:480 source = optimize(source, self)465 source = generate(source, self, name, filename,466 defer_init=defer_init)481 source = self._generate(source, name, filename,482 defer_init=defer_init)483 if raw:484 return source485 if filename is None:486 filename = '<template>'487 else:488 filename = _encode_filename(filename)473 return compile(source, filename, 'exec')489 return self._compile(source, filename)490 except TemplateSyntaxError:491 exc_info = sys.exc_info()492 self.handle_exception(exc_info, source_hint=source)493
110 unmodified lines
604605 filename = ModuleLoader.get_module_filename(name)606607 if py_compile:592 c = compile(code, _encode_filename(filename), 'exec')608 c = self._compile(code, _encode_filename(filename))609 write_file(filename + 'c', py_header +610 marshal.dumps(c), 'wb')611 log_function('Byte-compiled "%s" as %s' %612 (name, filename + 'c'))
506 unmodified lines