evaluate content at function start

This commit is contained in:
Paul Oswald 2014-07-29 22:13:11 +09:00
parent 921e4ed2ee
commit 66fa40c300

View File

@ -28,13 +28,14 @@ def dedent(content):
as it fails to dedent multiline docstrings that include as it fails to dedent multiline docstrings that include
unindented text on the initial line. unindented text on the initial line.
""" """
content = unicode(content)
whitespace_counts = [len(line) - len(line.lstrip(' ')) whitespace_counts = [len(line) - len(line.lstrip(' '))
for line in content.splitlines()[1:] if line.lstrip()] for line in content.splitlines()[1:] if line.lstrip()]
# unindent the content if needed # unindent the content if needed
if whitespace_counts: if whitespace_counts:
whitespace_pattern = '^' + (' ' * min(whitespace_counts)) whitespace_pattern = '^' + (' ' * min(whitespace_counts))
content = re.sub(re.compile(whitespace_pattern, re.MULTILINE), '', unicode(content)) content = re.sub(re.compile(whitespace_pattern, re.MULTILINE), '', content)
return content.strip() return content.strip()