Compile a node or template source code. The `name` parameter is the load name of the template after it was joined using :meth:`join_path` if necessary, not the filename on the file system. the `filename` parameter is the estimated filename of the template on the file
(self, source, name=None, filename=None, raw=False,
defer_init=False)
| 552 | |
| 553 | @internalcode |
| 554 | def compile(self, source, name=None, filename=None, raw=False, |
| 555 | defer_init=False): |
| 556 | """Compile a node or template source code. The `name` parameter is |
| 557 | the load name of the template after it was joined using |
| 558 | :meth:`join_path` if necessary, not the filename on the file system. |
| 559 | the `filename` parameter is the estimated filename of the template on |
| 560 | the file system. If the template came from a database or memory this |
| 561 | can be omitted. |
| 562 | |
| 563 | The return value of this method is a python code object. If the `raw` |
| 564 | parameter is `True` the return value will be a string with python |
| 565 | code equivalent to the bytecode returned otherwise. This method is |
| 566 | mainly used internally. |
| 567 | |
| 568 | `defer_init` is use internally to aid the module code generator. This |
| 569 | causes the generated code to be able to import without the global |
| 570 | environment variable to be set. |
| 571 | |
| 572 | .. versionadded:: 2.4 |
| 573 | `defer_init` parameter added. |
| 574 | """ |
| 575 | source_hint = None |
| 576 | try: |
| 577 | if isinstance(source, string_types): |
| 578 | source_hint = source |
| 579 | source = self._parse(source, name, filename) |
| 580 | source = self._generate(source, name, filename, |
| 581 | defer_init=defer_init) |
| 582 | if raw: |
| 583 | return source |
| 584 | if filename is None: |
| 585 | filename = '<template>' |
| 586 | else: |
| 587 | filename = encode_filename(filename) |
| 588 | return self._compile(source, filename) |
| 589 | except TemplateSyntaxError: |
| 590 | exc_info = sys.exc_info() |
| 591 | self.handle_exception(exc_info, source_hint=source_hint) |
| 592 | |
| 593 | def compile_expression(self, source, undefined_to_none=True): |
| 594 | """A handy helper method that returns a callable that accepts keyword |