diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-08 18:49:38 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-08 18:49:38 -0700 |
commit | b042d08429b95d76589ea69d14d7a44bcb32c3a1 (patch) | |
tree | 66d77563fc7dae00d3b69040753c6c0baff02d1a /pystache/renderer.py | |
parent | b06ea722e284e867dbc31e299bb1a1e9c5ba406c (diff) | |
download | pystache-b042d08429b95d76589ea69d14d7a44bcb32c3a1.tar.gz |
More unit tests for Python 3: type-checking in Renderer.render() for byte strings.
Diffstat (limited to 'pystache/renderer.py')
-rw-r--r-- | pystache/renderer.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pystache/renderer.py b/pystache/renderer.py index f16a95b..93be33b 100644 --- a/pystache/renderer.py +++ b/pystache/renderer.py @@ -5,6 +5,8 @@ This module provides a Renderer class to render templates. """ +import sys + from pystache import defaults from pystache.context import Context from pystache.loader import Loader @@ -13,6 +15,17 @@ from pystache.specloader import SpecLoader from pystache.template_spec import TemplateSpec +# TODO: come up with a better solution for this. One of the issues here +# is that in Python 3 there is no common base class for unicode strings +# and byte strings, and 2to3 seems to convert all of "str", "unicode", +# and "basestring" to Python 3's "str". +if sys.version_info < (3, ): + _STRING_TYPES = basestring +else: + # The latter evaluates to "bytes" in Python 3 -- even after conversion by 2to3. + _STRING_TYPES = (unicode, type(u"a".encode('utf-8'))) + + class Renderer(object): """ @@ -336,7 +349,7 @@ class Renderer(object): all items in the *context list. """ - if isinstance(template, basestring): + if isinstance(template, _STRING_TYPES): return self._render_string(template, *context, **kwargs) # Otherwise, we assume the template is an object. |