diff options
Diffstat (limited to 'sphinx/ext/pngmath.py')
-rw-r--r-- | sphinx/ext/pngmath.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index abac15cd..81a6f9d5 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import with_statement import re import codecs @@ -17,17 +16,16 @@ import tempfile import posixpath from os import path from subprocess import Popen, PIPE -try: - from hashlib import sha1 as sha -except ImportError: - from sha import sha +from hashlib import sha1 +from six import text_type from docutils import nodes +import sphinx from sphinx.errors import SphinxError from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.osutil import ensuredir, ENOENT, cd -from sphinx.util.pycompat import b, sys_encoding +from sphinx.util.pycompat import sys_encoding from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath class MathExtError(SphinxError): @@ -67,7 +65,7 @@ DOC_BODY_PREVIEW = r''' \end{document} ''' -depth_re = re.compile(b(r'\[\d+ depth=(-?\d+)\]')) +depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]') def render_math(self, math): """Render the LaTeX math expression *math* using latex and dvipng. @@ -86,9 +84,9 @@ def render_math(self, math): latex = DOC_HEAD + self.builder.config.pngmath_latex_preamble latex += (use_preview and DOC_BODY_PREVIEW or DOC_BODY) % math - shasum = "%s.png" % sha(latex.encode('utf-8')).hexdigest() + shasum = "%s.png" % sha1(latex.encode('utf-8')).hexdigest() relfn = posixpath.join(self.builder.imgpath, 'math', shasum) - outfn = path.join(self.builder.outdir, '_images', 'math', shasum) + outfn = path.join(self.builder.outdir, self.builder.imagedir, 'math', shasum) if path.isfile(outfn): depth = read_png_depth(outfn) return relfn, depth @@ -121,7 +119,7 @@ def render_math(self, math): with cd(tempdir): try: p = Popen(ltx_args, stdout=PIPE, stderr=PIPE) - except OSError, err: + except OSError as err: if err.errno != ENOENT: # No such file or directory raise self.builder.warn('LaTeX command %r cannot be run (needed for math ' @@ -146,7 +144,7 @@ def render_math(self, math): dvipng_args.append(path.join(tempdir, 'math.dvi')) try: p = Popen(dvipng_args, stdout=PIPE, stderr=PIPE) - except OSError, err: + except OSError as err: if err.errno != ENOENT: # No such file or directory raise self.builder.warn('dvipng command %r cannot be run (needed for math ' @@ -186,8 +184,8 @@ def get_tooltip(self, node): def html_visit_math(self, node): try: fname, depth = render_math(self, '$'+node['latex']+'$') - except MathExtError, exc: - msg = unicode(exc) + except MathExtError as exc: + msg = text_type(exc) sm = nodes.system_message(msg, type='WARNING', level=2, backrefs=[], source=node['latex']) sm.walkabout(self) @@ -211,7 +209,7 @@ def html_visit_displaymath(self, node): latex = wrap_displaymath(node['latex'], None) try: fname, depth = render_math(self, latex) - except MathExtError, exc: + except MathExtError as exc: sm = nodes.system_message(str(exc), type='WARNING', level=2, backrefs=[], source=node['latex']) sm.walkabout(self) @@ -243,3 +241,4 @@ def setup(app): app.add_config_value('pngmath_latex_preamble', '', 'html') app.add_config_value('pngmath_add_tooltips', True, 'html') app.connect('build-finished', cleanup_tempdir) + return {'version': sphinx.__version__, 'parallel_read_safe': True} |