Ticket #8316: trac_8316-remove_jinja.patch

File trac_8316-remove_jinja.patch, 3.0 KB (added by mpatel, 12 years ago)

Use Jinja2 instead of Jinja. sage repo.

  • sage/ext/gen_interpreters.py

    # 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 
    9898
    9999import os
    100100import re
    101 from jinja import Environment
    102 from jinja.datastructure import ComplainingUndefined
     101from jinja2 import Environment
     102from jinja2.runtime import StrictUndefined
    103103from collections import defaultdict
    104104from distutils.extension import Extension
    105105
    from distutils.extension import Extensio 
    114114##############################
    115115
    116116
    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.
     121jinja_env = Environment(trim_blocks=True, undefined=StrictUndefined)
     122
    123123# Allow 'i' as a shorter alias for the built-in 'indent' filter.
    124124jinja_env.filters['i'] = jinja_env.filters['indent']
    125125
    def je(template, **kwargs): 
    169169    if len(template) > 0 and template[0] == '\n':
    170170        template = template[1:]
    171171
    172     # It looks like Jinja automatically removes one trailing newline?
     172    # It looks like Jinja2 automatically removes one trailing newline?
    173173    if len(template) > 0 and template[-1] == '\n':
    174174        template = template + '\n'
    175175
  • sage/server/notebook/template.py

    diff --git a/sage/server/notebook/template.py b/sage/server/notebook/template.py
    a b AUTHORS: 
    2828#  The full text of the GPL is available at:
    2929#                  http://www.gnu.org/licenses/
    3030#############################################################################
    31 import jinja
     31import jinja2
    3232import sage.misc.misc
    3333from sage.version import version
    3434
    3535TEMPLATE_PATH = sage.misc.misc.SAGE_ROOT + '/devel/sage/sage/server/notebook/templates'
    36 env = jinja.Environment(loader=jinja.FileSystemLoader(TEMPLATE_PATH))
     36env = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_PATH))
    3737
    3838def contained_in(container):
    3939    """
    def template(filename, **user_context): 
    100100    """
    101101    try:
    102102        tmpl = env.get_template(filename)
    103     except jinja.exceptions.TemplateNotFound:
     103    except jinja2.exceptions.TemplateNotFound:
    104104        return template('template_error.html', template=filename)
    105105    context = dict(default_context)
    106106    context.update(user_context)