Commits

Jon Waltman committed baedd56

xml: Fix compatibility with docutils<0.9

  • Participants
  • Parent commits 376671b

Comments (0)

Files changed (2)

sphinx/builders/xml.py

 import codecs
 from os import path
 
+from docutils import nodes
 from docutils.io import StringOutput
 
 from sphinx.builders import Builder
         self.writer = self._writer_class(self)
 
     def write_doc(self, docname, doctree):
+        # work around multiple string % tuple issues in docutils;
+        # replace tuples in attribute values with lists
+        doctree = doctree.deepcopy()
+        for node in doctree.traverse(nodes.Element):
+            for att, value in node.attributes.items():
+                if isinstance(value, tuple):
+                    node.attributes[att] = list(value)
+                value = node.attributes[att]
+                if isinstance(value, list):
+                    for i, val in enumerate(value):
+                        if isinstance(val, tuple):
+                            value[i] = list(val)
         destination = StringOutput(encoding='utf-8')
         self.writer.write(doctree, destination)
         outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)

sphinx/writers/xml.py

 
 from docutils import writers
 from docutils.writers.docutils_xml import Writer as BaseXMLWriter
-from docutils.writers.docutils_xml import XMLTranslator as BaseXMLTranslator
 
 
 class XMLWriter(BaseXMLWriter):
         return BaseXMLWriter.translate(self)
 
 
-class XMLTranslator(BaseXMLTranslator):
-    def __init__(self, builder, doc):
-        BaseXMLTranslator.__init__(self, doc)
-        self.builder = builder
-
-
 class PseudoXMLWriter(writers.Writer):
 
     supported = ('pprint', 'pformat', 'pseudoxml')