summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-11 09:07:11 +0100
committerGeorg Brandl <georg@python.org>2014-01-11 09:07:11 +0100
commit818f76e027a2f4f7ea44dcf8dc70bee2a3118d8b (patch)
tree00ede1c38f2adde35fd2754de3d3cd078679ada5
parent4238b992b5e047c00a8a94df263e64fc8d1260db (diff)
downloadsphinx-818f76e027a2f4f7ea44dcf8dc70bee2a3118d8b.tar.gz
Closes #908: On Python 3, handle error messages from LaTeX correctly in the pngmath extension.
-rw-r--r--CHANGES3
-rw-r--r--sphinx/ext/pngmath.py10
-rw-r--r--sphinx/util/pycompat.py7
3 files changed, 15 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index e8d72d06..3077ee31 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,9 @@ Bugs fixed
* #933: Do not crash if an ``:option:`` value is malformed (contains spaces
but no option name).
+* #908: On Python 3, handle error messages from LaTeX correctly in the pngmath
+ extension.
+
Documentation
-------------
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py
index 3938dab1..a9a2203a 100644
--- a/sphinx/ext/pngmath.py
+++ b/sphinx/ext/pngmath.py
@@ -26,7 +26,7 @@ from docutils import nodes
from sphinx.errors import SphinxError
from sphinx.util.png import read_png_depth, write_png_depth
from sphinx.util.osutil import ensuredir, ENOENT
-from sphinx.util.pycompat import b
+from sphinx.util.pycompat import b, sys_encoding
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
class MathExtError(SphinxError):
@@ -34,9 +34,9 @@ class MathExtError(SphinxError):
def __init__(self, msg, stderr=None, stdout=None):
if stderr:
- msg += '\n[stderr]\n' + stderr
+ msg += '\n[stderr]\n' + stderr.decode(sys_encoding, 'replace')
if stdout:
- msg += '\n[stdout]\n' + stdout
+ msg += '\n[stdout]\n' + stdout.decode(sys_encoding, 'replace')
SphinxError.__init__(self, msg)
@@ -192,11 +192,11 @@ def html_visit_math(self, node):
try:
fname, depth = render_math(self, '$'+node['latex']+'$')
except MathExtError, exc:
- msg = unicode(str(exc), 'utf-8', 'replace')
+ msg = unicode(exc)
sm = nodes.system_message(msg, type='WARNING', level=2,
backrefs=[], source=node['latex'])
sm.walkabout(self)
- self.builder.warn('display latex %r: ' % node['latex'] + str(exc))
+ self.builder.warn('display latex %r: ' % node['latex'] + msg)
raise nodes.SkipNode
if fname is None:
# something failed -- use text-only as a bad substitute
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 3d252c91..1e5ea314 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -30,6 +30,9 @@ if sys.version_info >= (3, 0):
# safely encode a string for printing to the terminal
def terminal_safe(s):
return s.encode('ascii', 'backslashreplace').decode('ascii')
+ # some kind of default system encoding; should be used with a lenient
+ # error handler
+ sys_encoding = sys.getdefaultencoding()
# support for running 2to3 over config files
def convert_with_2to3(filepath):
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
@@ -62,6 +65,10 @@ else:
# safely encode a string for printing to the terminal
def terminal_safe(s):
return s.encode('ascii', 'backslashreplace')
+ # some kind of default system encoding; should be used with a lenient
+ # error handler
+ import locale
+ sys_encoding = locale.getpreferredencoding()
def execfile_(filepath, _globals):