Commit 8ad9282e by Chris Jerdonek

Fixed issue #68: "Remove output_encoding option from Renderer, etc."

parent 2c4cc815
...@@ -20,6 +20,7 @@ API changes: ...@@ -20,6 +20,7 @@ API changes:
* Template class replaced by a Renderer class. [cjerdonek] * Template class replaced by a Renderer class. [cjerdonek]
* ``Loader.load_template()`` changed to ``Loader.get()``. [cjerdonek] * ``Loader.load_template()`` changed to ``Loader.get()``. [cjerdonek]
* Removed output_encoding options. [cjerdonek]
Bug fixes: Bug fixes:
......
...@@ -40,7 +40,7 @@ class Renderer(object): ...@@ -40,7 +40,7 @@ class Renderer(object):
""" """
def __init__(self, loader=None, default_encoding=None, decode_errors='strict', def __init__(self, loader=None, default_encoding=None, decode_errors='strict',
output_encoding=None, escape=None): escape=None):
""" """
Construct an instance. Construct an instance.
...@@ -58,11 +58,6 @@ class Renderer(object): ...@@ -58,11 +58,6 @@ class Renderer(object):
default_encoding and decode_errors passed as the encoding and default_encoding and decode_errors passed as the encoding and
decode_errors arguments, respectively. decode_errors arguments, respectively.
output_encoding: the encoding to use when rendering to a string.
The argument should be the name of an encoding as a string, for
example "utf-8". See the render() method's documentation for
more information.
escape: the function used to escape variable tag values when escape: the function used to escape variable tag values when
rendering a template. The function should accept a unicode rendering a template. The function should accept a unicode
string (or subclass of unicode) and return an escaped string string (or subclass of unicode) and return an escaped string
...@@ -109,7 +104,6 @@ class Renderer(object): ...@@ -109,7 +104,6 @@ class Renderer(object):
self.default_encoding = default_encoding self.default_encoding = default_encoding
self.escape = escape self.escape = escape
self.loader = loader self.loader = loader
self.output_encoding = output_encoding
def _to_unicode_soft(self, s): def _to_unicode_soft(self, s):
""" """
...@@ -200,12 +194,8 @@ class Renderer(object): ...@@ -200,12 +194,8 @@ class Renderer(object):
""" """
Render the given template using the given context. Render the given template using the given context.
Returns: The return value is markupsafe.Markup if markup was importable
and unicode otherwise.
If the output_encoding attribute is None, the return value is
markupsafe.Markup if markup was importable and unicode if not.
Otherwise, the return value is encoded to a string of type str
using the output encoding named by the output_encoding attribute.
Arguments: Arguments:
...@@ -230,7 +220,4 @@ class Renderer(object): ...@@ -230,7 +220,4 @@ class Renderer(object):
rendered = engine.render(template, context) rendered = engine.render(template, context)
rendered = self._literal(rendered) rendered = self._literal(rendered)
if self.output_encoding is not None:
rendered = rendered.encode(self.output_encoding)
return rendered return rendered
...@@ -105,14 +105,14 @@ class View(object): ...@@ -105,14 +105,14 @@ class View(object):
# and options like encoding, escape, etc. This would probably be better # and options like encoding, escape, etc. This would probably be better
# than passing all of these options to render(), especially as the list # than passing all of these options to render(), especially as the list
# of possible options grows. # of possible options grows.
def render(self, encoding=None, escape=None): def render(self, escape=None):
""" """
Return the view rendered using the current context. Return the view rendered using the current context.
""" """
loader = self.get_loader() loader = self.get_loader()
template = self.get_template() template = self.get_template()
renderer = Renderer(output_encoding=encoding, escape=escape, loader=loader) renderer = Renderer(escape=escape, loader=loader)
return renderer.render(template, self.context) return renderer.render(template, self.context)
def get(self, key, default=None): def get(self, key, default=None):
......
...@@ -24,9 +24,6 @@ class TestView(unittest.TestCase): ...@@ -24,9 +24,6 @@ class TestView(unittest.TestCase):
def test_unicode_output(self): def test_unicode_output(self):
self.assertEquals(UnicodeOutput().render(), u'<p>Name: Henri Poincaré</p>') self.assertEquals(UnicodeOutput().render(), u'<p>Name: Henri Poincaré</p>')
def test_encoded_output(self):
self.assertEquals(UnicodeOutput().render('utf8'), '<p>Name: Henri Poincar\xc3\xa9</p>')
def test_unicode_input(self): def test_unicode_input(self):
self.assertEquals(UnicodeInput().render(), self.assertEquals(UnicodeInput().render(),
u'<p>If alive today, Henri Poincaré would be 156 years old.</p>') u'<p>If alive today, Henri Poincaré would be 156 years old.</p>')
......
...@@ -243,19 +243,12 @@ class RendererTestCase(unittest.TestCase): ...@@ -243,19 +243,12 @@ class RendererTestCase(unittest.TestCase):
renderer.render('Hi {{person}}', context=context, foo="bar") renderer.render('Hi {{person}}', context=context, foo="bar")
self.assertEquals(context, {}) self.assertEquals(context, {})
def test_render__output_encoding(self):
renderer = Renderer()
renderer.output_encoding = 'utf-8'
actual = renderer.render(u'Poincaré')
self.assertTrue(isinstance(actual, str))
self.assertEquals(actual, 'Poincaré')
def test_render__nonascii_template(self): def test_render__nonascii_template(self):
""" """
Test passing a non-unicode template with non-ascii characters. Test passing a non-unicode template with non-ascii characters.
""" """
renderer = Renderer(output_encoding="utf-8") renderer = Renderer()
template = "déf" template = "déf"
# Check that decode_errors and default_encoding are both respected. # Check that decode_errors and default_encoding are both respected.
...@@ -264,7 +257,7 @@ class RendererTestCase(unittest.TestCase): ...@@ -264,7 +257,7 @@ class RendererTestCase(unittest.TestCase):
self.assertEquals(renderer.render(template), "df") self.assertEquals(renderer.render(template), "df")
renderer.default_encoding = 'utf_8' renderer.default_encoding = 'utf_8'
self.assertEquals(renderer.render(template), "déf") self.assertEquals(renderer.render(template), u"déf")
def test_make_load_partial(self): def test_make_load_partial(self):
""" """
......
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