summaryrefslogtreecommitdiff
path: root/pystache/common.py
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-10-20 15:57:23 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-10-20 15:57:23 -0700
commitba5ef6d31eb2705df846444b56893b555948fbf8 (patch)
treeadf04a7e2df34a7442b448573593cf316b3fca88 /pystache/common.py
parentb8a3d0c6cea62874bac2414db2c06856293d8877 (diff)
parent5e9a226992ce9b3c9fa1ecd9de700b8d8ff4f136 (diff)
downloadpystache-ba5ef6d31eb2705df846444b56893b555948fbf8.tar.gz
Merge branch 'development' into 'master': staging v0.5.3-rc
Diffstat (limited to 'pystache/common.py')
-rw-r--r--pystache/common.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/pystache/common.py b/pystache/common.py
index c1fd7a1..fb266dd 100644
--- a/pystache/common.py
+++ b/pystache/common.py
@@ -5,6 +5,33 @@ Exposes functionality needed throughout the project.
"""
+from sys import version_info
+
+def _get_string_types():
+ # 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 version_info < (3, ):
+ return basestring
+ # The latter evaluates to "bytes" in Python 3 -- even after conversion by 2to3.
+ return (unicode, type(u"a".encode('utf-8')))
+
+
+_STRING_TYPES = _get_string_types()
+
+
+def is_string(obj):
+ """
+ Return whether the given object is a byte string or unicode string.
+
+ This function is provided for compatibility with both Python 2 and 3
+ when using 2to3.
+
+ """
+ return isinstance(obj, _STRING_TYPES)
+
+
# This function was designed to be portable across Python versions -- both
# with older versions and with Python 3 after applying 2to3.
def read(path):
@@ -26,6 +53,14 @@ def read(path):
f.close()
+class MissingTags(object):
+
+ """Contains the valid values for Renderer.missing_tags."""
+
+ ignore = 'ignore'
+ strict = 'strict'
+
+
class PystacheError(Exception):
"""Base class for Pystache exceptions."""
pass