# HG changeset patch
# User Mitesh Patel <qed777@gmail.com>
# Date 1267754767 28800
# Node ID 3c274856b2539082f75aa643449098595cb90838
# Parent c49613dc3a07d8be9cd9ae50384e322cd010855c
#8316: Use Jinja2 instead of Jinja
diff --git a/sage/ext/gen_interpreters.py b/sage/ext/gen_interpreters.py
a
|
b
|
from __future__ import with_statement |
98 | 98 | |
99 | 99 | import os |
100 | 100 | import re |
101 | | from jinja import Environment |
102 | | from jinja.datastructure import ComplainingUndefined |
| 101 | from jinja2 import Environment |
| 102 | from jinja2.runtime import StrictUndefined |
103 | 103 | from collections import defaultdict |
104 | 104 | from distutils.extension import Extension |
105 | 105 | |
… |
… |
from distutils.extension import Extensio |
114 | 114 | ############################## |
115 | 115 | |
116 | 116 | |
117 | | # We share a single jinja environment among all templating in this file. |
118 | | # We use trim_blocks=True (which means that we ignore white space after |
119 | | # "%}" jinja command endings), and set undefined_singleton to complain |
120 | | # if we use an undefined variable. |
121 | | jinja_env = Environment(trim_blocks=True, |
122 | | undefined_singleton=ComplainingUndefined) |
| 117 | # We share a single jinja2 environment among all templating in this |
| 118 | # file. We use trim_blocks=True (which means that we ignore white |
| 119 | # space after "%}" jinja2 command endings), and set undefined to |
| 120 | # complain if we use an undefined variable. |
| 121 | jinja_env = Environment(trim_blocks=True, undefined=StrictUndefined) |
| 122 | |
123 | 123 | # Allow 'i' as a shorter alias for the built-in 'indent' filter. |
124 | 124 | jinja_env.filters['i'] = jinja_env.filters['indent'] |
125 | 125 | |
… |
… |
def je(template, **kwargs): |
169 | 169 | if len(template) > 0 and template[0] == '\n': |
170 | 170 | template = template[1:] |
171 | 171 | |
172 | | # It looks like Jinja automatically removes one trailing newline? |
| 172 | # It looks like Jinja2 automatically removes one trailing newline? |
173 | 173 | if len(template) > 0 and template[-1] == '\n': |
174 | 174 | template = template + '\n' |
175 | 175 | |
diff --git a/sage/server/notebook/template.py b/sage/server/notebook/template.py
a
|
b
|
AUTHORS: |
28 | 28 | # The full text of the GPL is available at: |
29 | 29 | # http://www.gnu.org/licenses/ |
30 | 30 | ############################################################################# |
31 | | import jinja |
| 31 | import jinja2 |
32 | 32 | import sage.misc.misc |
33 | 33 | from sage.version import version |
34 | 34 | |
35 | 35 | TEMPLATE_PATH = sage.misc.misc.SAGE_ROOT + '/devel/sage/sage/server/notebook/templates' |
36 | | env = jinja.Environment(loader=jinja.FileSystemLoader(TEMPLATE_PATH)) |
| 36 | env = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_PATH)) |
37 | 37 | |
38 | 38 | def contained_in(container): |
39 | 39 | """ |
… |
… |
def template(filename, **user_context): |
100 | 100 | """ |
101 | 101 | try: |
102 | 102 | tmpl = env.get_template(filename) |
103 | | except jinja.exceptions.TemplateNotFound: |
| 103 | except jinja2.exceptions.TemplateNotFound: |
104 | 104 | return template('template_error.html', template=filename) |
105 | 105 | context = dict(default_context) |
106 | 106 | context.update(user_context) |