Commit 63d6dd49 by Chris Jerdonek

Python 3 support: use html module instead of cgi.escape().

Python 3.2 deprecates cgi.escape() and introduces the html module in its place.
parent 93a58fc0
......@@ -8,7 +8,12 @@ does not otherwise specify a value.
"""
import cgi
try:
# Python 3.2 deprecates cgi.escape() and adds the html module as a replacement.
import html
except ImportError:
import cgi as html
import os
import sys
......@@ -42,9 +47,10 @@ SEARCH_DIRS = [os.curdir] # i.e. ['.']
# The quote=True argument causes double quotes to be escaped,
# but not single quotes:
#
# http://docs.python.org/dev/library/html.html#html.escape
# http://docs.python.org/library/cgi.html#cgi.escape
#
TAG_ESCAPE = lambda u: cgi.escape(u, quote=True)
TAG_ESCAPE = lambda u: html.escape(u, quote=True)
# The default template extension.
TEMPLATE_EXTENSION = 'mustache'
......@@ -64,10 +64,10 @@ class Renderer(object):
this class will only pass it unicode strings. The constructor
assigns this function to the constructed instance's escape()
method.
The argument defaults to `cgi.escape(s, quote=True)`. To
disable escaping entirely, one can pass `lambda u: u` as the
escape function, for example. One may also wish to consider
using markupsafe's escape function: markupsafe.escape().
To disable escaping entirely, one can pass `lambda u: u`
as the escape function, for example. One may also wish to
consider using markupsafe's escape function: markupsafe.escape().
This argument defaults to the package default.
file_encoding: the name of the default encoding to use when reading
template files. All templates are converted to unicode prior
......
......@@ -5,10 +5,10 @@ Unit tests of renderengine.py.
"""
import cgi
import unittest
from pystache.context import Context
from pystache import defaults
from pystache.parser import ParsingError
from pystache.renderengine import RenderEngine
from pystache.tests.common import AssertStringMixin
......@@ -47,7 +47,7 @@ class RenderTests(unittest.TestCase, AssertStringMixin):
Create and return a default RenderEngine for testing.
"""
escape = lambda s: unicode(cgi.escape(s))
escape = defaults.TAG_ESCAPE
engine = RenderEngine(literal=unicode, escape=escape, load_partial=None)
return engine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment