diff --git a/CHANGES b/CHANGES index bf38ffa71..289b64856 100644 --- a/CHANGES +++ b/CHANGES @@ -70,6 +70,7 @@ Deprecated ``IndexBuilder.feed()`` method is deprecated. * ``sphinx.addnodes.abbreviation`` * ``sphinx.application.Sphinx._setting_up_extension`` +* ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()`` * ``sphinx.cmd.quickstart.term_decode()`` * ``sphinx.cmd.quickstart.TERM_ENCODING`` * ``sphinx.config.check_unicode()`` diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index dcfd4fbd7..66965b795 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -263,6 +263,11 @@ The following is a list of deprecated interfaces. - 4.0 - ``docutils.nodes.abbreviation`` + * - ``sphinx.builders.htmlhelp.HTMLHelpBuilder.open_file()`` + - 2.0 + - 4.0 + - ``open()`` + * - ``sphinx.cmd.quickstart.term_decode()`` - 2.0 - 4.0 diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index a2b61eabe..582bbbb12 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -11,12 +11,14 @@ import html import os +import warnings from os import path from docutils import nodes from sphinx import addnodes from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.deprecation import RemovedInSphinx40Warning from sphinx.environment.adapters.indexentries import IndexEntries from sphinx.locale import __ from sphinx.util import logging @@ -221,6 +223,8 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def open_file(self, outdir, basename, mode='w'): # type: (str, str, str) -> IO # open a file with the correct encoding for the selected language + warnings.warn('HTMLHelpBuilder.open_file() is deprecated.', + RemovedInSphinx40Warning) return open(path.join(outdir, basename), mode, encoding=self.encoding, errors='xmlcharrefreplace') @@ -244,12 +248,14 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def build_hhx(self, outdir, outname): # type: (str, str) -> None logger.info(__('dumping stopword list...')) - with self.open_file(outdir, outname + '.stp') as f: + filename = path.join(outdir, outname + '.stp') + with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f: for word in sorted(stopwords): print(word, file=f) logger.info(__('writing project file...')) - with self.open_file(outdir, outname + '.hhp') as f: + filename = path.join(outdir, outname + '.hhp') + with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f: f.write(project_template % { 'outname': outname, 'title': self.config.html_title, @@ -272,7 +278,8 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): file=f) logger.info(__('writing TOC file...')) - with self.open_file(outdir, outname + '.hhc') as f: + filename = path.join(outdir, outname + '.hhc') + with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f: f.write(contents_header) # special books f.write('