summaryrefslogtreecommitdiff
path: root/pystache/renderer.py
diff options
context:
space:
mode:
Diffstat (limited to 'pystache/renderer.py')
-rw-r--r--pystache/renderer.py15
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.