mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #908: On Python 3, handle error messages from LaTeX correctly in the pngmath extension.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -33,6 +33,9 @@ Bugs fixed
|
|||||||
* #933: Do not crash if an ``:option:`` value is malformed (contains spaces
|
* #933: Do not crash if an ``:option:`` value is malformed (contains spaces
|
||||||
but no option name).
|
but no option name).
|
||||||
|
|
||||||
|
* #908: On Python 3, handle error messages from LaTeX correctly in the pngmath
|
||||||
|
extension.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from docutils import nodes
|
|||||||
from sphinx.errors import SphinxError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.util.png import read_png_depth, write_png_depth
|
from sphinx.util.png import read_png_depth, write_png_depth
|
||||||
from sphinx.util.osutil import ensuredir, ENOENT
|
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
|
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
|
||||||
|
|
||||||
class MathExtError(SphinxError):
|
class MathExtError(SphinxError):
|
||||||
@@ -34,9 +34,9 @@ class MathExtError(SphinxError):
|
|||||||
|
|
||||||
def __init__(self, msg, stderr=None, stdout=None):
|
def __init__(self, msg, stderr=None, stdout=None):
|
||||||
if stderr:
|
if stderr:
|
||||||
msg += '\n[stderr]\n' + stderr
|
msg += '\n[stderr]\n' + stderr.decode(sys_encoding, 'replace')
|
||||||
if stdout:
|
if stdout:
|
||||||
msg += '\n[stdout]\n' + stdout
|
msg += '\n[stdout]\n' + stdout.decode(sys_encoding, 'replace')
|
||||||
SphinxError.__init__(self, msg)
|
SphinxError.__init__(self, msg)
|
||||||
|
|
||||||
|
|
||||||
@@ -192,11 +192,11 @@ def html_visit_math(self, node):
|
|||||||
try:
|
try:
|
||||||
fname, depth = render_math(self, '$'+node['latex']+'$')
|
fname, depth = render_math(self, '$'+node['latex']+'$')
|
||||||
except MathExtError, exc:
|
except MathExtError, exc:
|
||||||
msg = unicode(str(exc), 'utf-8', 'replace')
|
msg = unicode(exc)
|
||||||
sm = nodes.system_message(msg, type='WARNING', level=2,
|
sm = nodes.system_message(msg, type='WARNING', level=2,
|
||||||
backrefs=[], source=node['latex'])
|
backrefs=[], source=node['latex'])
|
||||||
sm.walkabout(self)
|
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
|
raise nodes.SkipNode
|
||||||
if fname is None:
|
if fname is None:
|
||||||
# something failed -- use text-only as a bad substitute
|
# something failed -- use text-only as a bad substitute
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ if sys.version_info >= (3, 0):
|
|||||||
# safely encode a string for printing to the terminal
|
# safely encode a string for printing to the terminal
|
||||||
def terminal_safe(s):
|
def terminal_safe(s):
|
||||||
return s.encode('ascii', 'backslashreplace').decode('ascii')
|
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
|
# support for running 2to3 over config files
|
||||||
def convert_with_2to3(filepath):
|
def convert_with_2to3(filepath):
|
||||||
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
||||||
@@ -62,6 +65,10 @@ else:
|
|||||||
# safely encode a string for printing to the terminal
|
# safely encode a string for printing to the terminal
|
||||||
def terminal_safe(s):
|
def terminal_safe(s):
|
||||||
return s.encode('ascii', 'backslashreplace')
|
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):
|
def execfile_(filepath, _globals):
|
||||||
|
|||||||
Reference in New Issue
Block a user