Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def p(x=None, f=None):
if x is None and f is not None:
x = e.loader.get_source(f)
print PythonTranslator(e, Parser(e, x, f).parse(), None).translate()
def from_string(self, source):
"""
Load and parse a template source and translate it into eval-able
Python code. This code is wrapped within a `Template` class that
allows you to render it.
"""
from jinja.translators.python import PythonTranslator
try:
rv = PythonTranslator.process(self, Parser(self, source).parse(),
source)
except TemplateSyntaxError, e:
# on syntax errors rewrite the traceback if wanted
if not self.friendly_traceback:
raise
from jinja.debugger import raise_syntax_error
if __debug__:
__traceback_hide__ = True
raise_syntax_error(e, self, source)
else:
return rv
def parse(self, source, filename=None):
"""
Parse the sourcecode and return the abstract syntax tree. This tree
of nodes is used by the `translators`_ to convert the template into
executable source- or bytecode.
.. _translators: translators.txt
"""
parser = Parser(self, source, filename)
return parser.parse()
def parse(self, environment, name, parent):
"""
Load and parse a template
"""
source = self.get_source(environment, name, parent)
return Parser(environment, source, name).parse()