diff options
Diffstat (limited to 'sphinx/builders/xml.py')
-rw-r--r-- | sphinx/builders/xml.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py index 6198532c9..6c6d5a9d8 100644 --- a/sphinx/builders/xml.py +++ b/sphinx/builders/xml.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.builders.xml ~~~~~~~~~~~~~~~~~~~ @@ -9,7 +8,6 @@ :license: BSD, see LICENSE for details. """ -import codecs from os import path from docutils import nodes @@ -24,7 +22,8 @@ from sphinx.writers.xml import XMLWriter, PseudoXMLWriter if False: # For type annotation - from typing import Any, Dict, Iterator, Set # NOQA + from typing import Any, Dict, Iterator, Set, Type # NOQA + from docutils.writers.xml import BaseXMLWriter # NOQA from sphinx.application import Sphinx # NOQA logger = logging.getLogger(__name__) @@ -41,7 +40,7 @@ class XMLBuilder(Builder): out_suffix = '.xml' allow_parallel = True - _writer_class = XMLWriter + _writer_class = XMLWriter # type: Type[BaseXMLWriter] default_translator_class = XMLTranslator def init(self): @@ -49,13 +48,12 @@ class XMLBuilder(Builder): pass def get_outdated_docs(self): - # type: () -> Iterator[unicode] + # type: () -> Iterator[str] for docname in self.env.found_docs: if docname not in self.env.all_docs: yield docname continue - targetname = self.env.doc2path(docname, self.outdir, - self.out_suffix) + targetname = path.join(self.outdir, docname + self.out_suffix) try: targetmtime = path.getmtime(targetname) except Exception: @@ -64,20 +62,20 @@ class XMLBuilder(Builder): srcmtime = path.getmtime(self.env.doc2path(docname)) if srcmtime > targetmtime: yield docname - except EnvironmentError: + except OSError: # source doesn't exist anymore pass def get_target_uri(self, docname, typ=None): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str return docname def prepare_writing(self, docnames): - # type: (Set[unicode]) -> None + # type: (Set[str]) -> None self.writer = self._writer_class(self) def write_doc(self, docname, doctree): - # type: (unicode, nodes.Node) -> None + # type: (str, nodes.Node) -> None # work around multiple string % tuple issues in docutils; # replace tuples in attribute values with lists doctree = doctree.deepcopy() @@ -95,9 +93,9 @@ class XMLBuilder(Builder): outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix) ensuredir(path.dirname(outfilename)) try: - with codecs.open(outfilename, 'w', 'utf-8') as f: # type: ignore + with open(outfilename, 'w', encoding='utf-8') as f: f.write(self.writer.output) - except (IOError, OSError) as err: + except OSError as err: logger.warning(__("error writing file %s: %s"), outfilename, err) def finish(self): @@ -119,7 +117,7 @@ class PseudoXMLBuilder(XMLBuilder): def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_builder(XMLBuilder) app.add_builder(PseudoXMLBuilder) |