summaryrefslogtreecommitdiff
path: root/sphinx/util/pycompat.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/pycompat.py')
-rw-r--r--sphinx/util/pycompat.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 519afe5fe..b3e50474a 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -48,6 +48,13 @@ if six.PY3:
return six.text_type(tree)
from html import escape as htmlescape # >= Python 3.2
+ class UnicodeMixin:
+ """Mixin class to handle defining the proper __str__/__unicode__
+ methods in Python 2 or 3."""
+
+ def __str__(self):
+ return self.__unicode__()
+
else:
# Python 2
b = str
@@ -65,6 +72,13 @@ else:
# use Python 3 name
from cgi import escape as htmlescape # 2.6, 2.7
+ class UnicodeMixin(object):
+ """Mixin class to handle defining the proper __str__/__unicode__
+ methods in Python 2 or 3."""
+
+ def __str__(self):
+ return self.__unicode__().encode('utf8')
+
def execfile_(filepath, _globals):
from sphinx.util.osutil import fs_encoding