Created
February 28, 2014 13:28
-
-
Save mrvdb/9271115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We use a jinja2 sandboxed environment to render mako templates. | |
# Note that the rendering does not cover all the mako syntax, in particular | |
# arbitrary Python statements are not accepted, and not all expressions are | |
# allowed: only "public" attributes (not starting with '_') of objects may | |
# be accessed. | |
# This is done on purpose: it prevents incidental or malicious execution of | |
# Python code that may break the security of the server. | |
from jinja2.sandbox import SandboxedEnvironment | |
mako_template_env = SandboxedEnvironment( | |
block_start_string="<%", | |
block_end_string="%>", | |
variable_start_string="${", | |
variable_end_string="}", | |
comment_start_string="<%doc>", | |
comment_end_string="</%doc>", | |
line_statement_prefix="%", | |
line_comment_prefix="##", | |
trim_blocks=True, # do not output newline after blocks | |
autoescape=True, # XML/HTML automatic escaping | |
) | |
mako_template_env.globals.update({ | |
'str': str, | |
'quote': quote, | |
'urlencode': urlencode, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment