Some docstring bugs fixed, some remain...

I had broken escaping the tail quote by inadvertently switching from """
by default to '''.

Some additional tests have been added to 00_docstring.py for
this. However...

Unicode decoding is still broken. For now I've added  errors="ignore" to
.decode("utf-8", ...) until a better fix is found. Sigh.
This commit is contained in:
rocky
2019-05-27 16:12:50 -04:00
parent e364499bb9
commit f7697ccd7b
3 changed files with 52 additions and 22 deletions

View File

@@ -100,8 +100,10 @@ def strip_quotes(str):
def print_docstring(self, indent, docstring):
quote = '"""'
if docstring.find("'''") == -1:
quote = "'''"
if docstring.find(quote) >= 0:
if docstring.find("'''") == -1:
quote = "'''"
self.write(indent)
if not PYTHON3 and not isinstance(docstring, str):
# Must be unicode in Python2
@@ -110,7 +112,8 @@ def print_docstring(self, indent, docstring):
docstring = repr(docstring.expandtabs())[2:-1].decode("unicode-escape")
else:
self.write('u')
docstring = repr(docstring.expandtabs())[2:-1].decode("string-escape").decode("utf-8")
docstring = repr(docstring.expandtabs())[2:-1].decode("string-escape")\
.decode("utf-8", errors="ignore")
else:
docstring = repr(docstring.expandtabs())[2:-1]
elif PYTHON3 and 2.4 <= self.version <= 2.7:
@@ -143,10 +146,11 @@ def print_docstring(self, indent, docstring):
# Restore backslashes unescaped since raw
docstring = docstring.replace('\t', '\\')
else:
# Escape '"' if it's the last character, so it doesn't
# ruin the ending triple quote
if len(docstring) and docstring[-1] == '"':
docstring = docstring[:-1] + '\\"'
# Escape the last character if it is the same as the
# triple quote character.
quote1 = quote[-1]
if len(docstring) and docstring[-1] == quote1:
docstring = docstring[:-1] + '\\' + quote1
# Escape triple quote when needed
if quote == '"""':