Commit e29f92b8 by Chris Jerdonek

Fixed test case: test__escape_preserves_unicode_subclasses in test_renderengine.py.

parent 373ba016
......@@ -389,17 +389,21 @@ class Template(object):
def partial(self, name, context=None):
return context.partial(name)
def escape_tag_function(self, name):
get_literal = self.literal_tag_function(name)
def func(context):
u = get_literal(context)
u = self.escape(u)
return u
return func
def _get_string_value(self, context, tag_name):
"""
Get a value from the given context as a basestring instance.
def literal_tag_function(self, name):
def func(context):
val = context.get(name)
"""
val = context.get(tag_name)
# We use "==" rather than "is" to compare integers, as using "is"
# relies on an implementation detail of CPython. The test about
# rendering zeroes failed while using PyPy when using "is".
# See issue #34: https://github.com/defunkt/pystache/issues/34
if not val and val != 0:
if tag_name != '.':
return ''
val = self.context.top()
if callable(val):
# According to the spec:
......@@ -412,8 +416,25 @@ class Template(object):
template = val()
val = self.render_template(template, context)
u = self.to_unicode(val)
return u
if not isinstance(val, basestring):
val = str(val)
return val
def escape_tag_function(self, name):
get_literal = self.literal_tag_function(name)
def func(context):
s = self._get_string_value(context, name)
s = self.escape(s)
return s
return func
def literal_tag_function(self, name):
def func(context):
s = self._get_string_value(context, name)
s = self.to_unicode(s)
return s
return func
......
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