diff options
Diffstat (limited to 'sphinx/builders/changes.py')
-rw-r--r-- | sphinx/builders/changes.py | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py index 3f9bffa0d..b6cfaa60b 100644 --- a/sphinx/builders/changes.py +++ b/sphinx/builders/changes.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.builders.changes ~~~~~~~~~~~~~~~~~~~~~~~ @@ -9,12 +8,10 @@ :license: BSD, see LICENSE for details. """ -import codecs +import html from os import path from typing import cast -from six import iteritems - from sphinx import package_dir from sphinx.builders import Builder from sphinx.domains.changeset import ChangeSetDomain @@ -24,7 +21,6 @@ from sphinx.util import logging from sphinx.util.console import bold # type: ignore from sphinx.util.fileutil import copy_asset_file from sphinx.util.osutil import ensuredir, os_path -from sphinx.util.pycompat import htmlescape if False: # For type annotation @@ -50,22 +46,22 @@ class ChangesBuilder(Builder): self.templates.init(self, self.theme) def get_outdated_docs(self): - # type: () -> unicode + # type: () -> str return self.outdir typemap = { 'versionadded': 'added', 'versionchanged': 'changed', 'deprecated': 'deprecated', - } # type: Dict[unicode, unicode] + } def write(self, *ignored): # type: (Any) -> None version = self.config.version domain = cast(ChangeSetDomain, self.env.get_domain('changeset')) - libchanges = {} # type: Dict[unicode, List[Tuple[unicode, unicode, int]]] - apichanges = [] # type: List[Tuple[unicode, unicode, int]] - otherchanges = {} # type: Dict[Tuple[unicode, unicode], List[Tuple[unicode, unicode, int]]] # NOQA + libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]] + apichanges = [] # type: List[Tuple[str, str, int]] + otherchanges = {} # type: Dict[Tuple[str, str], List[Tuple[str, str, int]]] if version not in self.env.versionchanges: logger.info(bold(__('no changes in version %s.') % version)) return @@ -109,15 +105,15 @@ class ChangesBuilder(Builder): 'version': version, 'docstitle': self.config.html_title, 'shorttitle': self.config.html_short_title, - 'libchanges': sorted(iteritems(libchanges)), + 'libchanges': sorted(libchanges.items()), 'apichanges': sorted(apichanges), - 'otherchanges': sorted(iteritems(otherchanges)), + 'otherchanges': sorted(otherchanges.items()), 'show_copyright': self.config.html_show_copyright, 'show_sphinx': self.config.html_show_sphinx, } - with codecs.open(path.join(self.outdir, 'index.html'), 'w', 'utf8') as f: # type: ignore # NOQA + with open(path.join(self.outdir, 'index.html'), 'w', encoding='utf8') as f: f.write(self.templates.render('changes/frameset.html', ctx)) - with codecs.open(path.join(self.outdir, 'changes.html'), 'w', 'utf8') as f: # type: ignore # NOQA + with open(path.join(self.outdir, 'changes.html'), 'w', encoding='utf8') as f: f.write(self.templates.render('changes/versionchanges.html', ctx)) hltext = ['.. versionadded:: %s' % version, @@ -125,8 +121,8 @@ class ChangesBuilder(Builder): '.. deprecated:: %s' % version] def hl(no, line): - # type: (int, unicode) -> unicode - line = '<a name="L%s"> </a>' % no + htmlescape(line) + # type: (int, str) -> str + line = '<a name="L%s"> </a>' % no + html.escape(line) for x in hltext: if x in line: line = '<span class="hl">%s</span>' % line @@ -135,8 +131,8 @@ class ChangesBuilder(Builder): logger.info(bold(__('copying source files...'))) for docname in self.env.all_docs: - with codecs.open(self.env.doc2path(docname), 'r', # type: ignore - self.env.config.source_encoding) as f: + with open(self.env.doc2path(docname), + encoding=self.env.config.source_encoding) as f: try: lines = f.readlines() except UnicodeDecodeError: @@ -144,7 +140,7 @@ class ChangesBuilder(Builder): continue targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html' ensuredir(path.dirname(targetfn)) - with codecs.open(targetfn, 'w', 'utf-8') as f: # type: ignore + with open(targetfn, 'w', encoding='utf-8') as f: text = ''.join(hl(i + 1, line) for (i, line) in enumerate(lines)) ctx = { 'filename': self.env.doc2path(docname, None), @@ -152,15 +148,15 @@ class ChangesBuilder(Builder): } f.write(self.templates.render('changes/rstsource.html', ctx)) themectx = dict(('theme_' + key, val) for (key, val) in - iteritems(self.theme.get_options({}))) + self.theme.get_options({}).items()) copy_asset_file(path.join(package_dir, 'themes', 'default', 'static', 'default.css_t'), self.outdir, context=themectx, renderer=self.templates) copy_asset_file(path.join(package_dir, 'themes', 'basic', 'static', 'basic.css'), self.outdir) def hl(self, text, version): - # type: (unicode, unicode) -> unicode - text = htmlescape(text) + # type: (str, str) -> str + text = html.escape(text) for directive in ['versionchanged', 'versionadded', 'deprecated']: text = text.replace('.. %s:: %s' % (directive, version), '<b>.. %s:: %s</b>' % (directive, version)) @@ -172,7 +168,7 @@ class ChangesBuilder(Builder): def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_builder(ChangesBuilder) return { |