Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyramid scaffolding collides with jinja2 templating #534

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion pyramid/scaffolds/template.py
Expand Up @@ -35,7 +35,8 @@ def render_template(self, content, vars, filename=None):
content = native_(content, fsenc)
try:
return bytes_(
substitute_double_braces(content, TypeMapper(vars)), fsenc)
substitute_escaped_double_braces(
substitute_double_braces(content, TypeMapper(vars))), fsenc)
except Exception as e:
_add_except(e, ' in file %s' % filename)
raise
Expand Down Expand Up @@ -149,6 +150,14 @@ def double_bracerepl(match):
return values[value]
return double_brace_pattern.sub(double_bracerepl, content)

escaped_double_brace_pattern = re.compile(r'\\{\\{(?P<escape_braced>.*?)\\}\\}')

def substitute_escaped_double_braces(content):
def escaped_double_bracerepl(match):
value = match.group('escape_braced').strip()
return "{{%(value)s}}" % locals()
return escaped_double_brace_pattern.sub(escaped_double_bracerepl, content)

def _add_except(exc, info): # pragma: no cover
if not hasattr(exc, 'args') or exc.args is None:
return
Expand Down