From b5f351064c8b51672fcae7b9aa6e5634338cc593 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Fri, 15 Aug 2014 00:31:21 +0900 Subject: [PATCH 1/2] * importing the pull request #270 change to stable: Non-ASCII docstring cause UnicodeDecodeError when uses with inheritance-diagram directive. Thanks to WAKAYAMA shirou. Closes #1533 --- CHANGES | 2 ++ sphinx/ext/inheritance_diagram.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 45926f271..7b03425f1 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,8 @@ Bugs fixed texinfo and changes. * #1531: On Python3 environment, docutils.conf with 'source_link=true' in the general section cause type error. +* PR#270, #1533: Non-ASCII docstring cause UnicodeDecodeError when uses with + inheritance-diagram directive. Thanks to WAKAYAMA shirou. Release 1.2.2 (released Mar 2, 2014) ==================================== diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index d10b89ccc..0445781bc 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -50,6 +50,7 @@ from docutils.parsers.rst import directives from sphinx.ext.graphviz import render_dot_html, render_dot_latex, \ render_dot_texinfo +from sphinx.pycode import ModuleAnalyzer from sphinx.util.compat import Directive @@ -158,7 +159,9 @@ class InheritanceGraph(object): tooltip = None try: if cls.__doc__: + enc = ModuleAnalyzer.for_module(cls.__module__).encoding doc = cls.__doc__.strip().split("\n")[0] + doc = doc.decode(enc) if doc: tooltip = '"%s"' % doc.replace('"', '\\"') except Exception: # might raise AttributeError for strange classes From acf1276d39b8670125bc4da8c0fb8690b30b5da8 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Fri, 15 Aug 2014 22:21:19 +0900 Subject: [PATCH 2/2] ues sphinx.util.force_decode if doc is not unicode. --- sphinx/ext/inheritance_diagram.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 0445781bc..5b8eab3f9 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -51,6 +51,7 @@ from docutils.parsers.rst import directives from sphinx.ext.graphviz import render_dot_html, render_dot_latex, \ render_dot_texinfo from sphinx.pycode import ModuleAnalyzer +from sphinx.util import force_decode from sphinx.util.compat import Directive @@ -161,7 +162,8 @@ class InheritanceGraph(object): if cls.__doc__: enc = ModuleAnalyzer.for_module(cls.__module__).encoding doc = cls.__doc__.strip().split("\n")[0] - doc = doc.decode(enc) + if not isinstance(doc, unicode): + doc = force_decode(doc, enc) if doc: tooltip = '"%s"' % doc.replace('"', '\\"') except Exception: # might raise AttributeError for strange classes