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.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index e01177744..a3ea36ba4 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -52,6 +52,8 @@ if PY3:
def __str__(self):
return self.__unicode__()
+ from textwrap import indent
+
else:
# Python 2
u = 'u'
@@ -75,6 +77,17 @@ else:
def __str__(self):
return self.__unicode__().encode('utf8')
+ # backport from python3
+ def indent(text, prefix, predicate=None):
+ if predicate is None:
+ def predicate(line):
+ return line.strip()
+
+ def prefixed_lines():
+ for line in text.splitlines(True):
+ yield (prefix + line if predicate(line) else line)
+ return ''.join(prefixed_lines())
+
def execfile_(filepath, _globals, open=open):
from sphinx.util.osutil import fs_encoding