summaryrefslogtreecommitdiff
path: root/docutils/writers/docutils_xml.py
diff options
context:
space:
mode:
authoraa-turner <aa-turner@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-02 23:28:49 +0000
committeraa-turner <aa-turner@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-02 23:28:49 +0000
commit92f3753fda69c27c968e65378137f65454122fa0 (patch)
treecd08efb567e8c0a39d56310f22cd84b15c34226c /docutils/writers/docutils_xml.py
parent1415ac0f4ed65a3d0c155060a024f3444f8c866e (diff)
downloaddocutils-92f3753fda69c27c968e65378137f65454122fa0.tar.gz
Partially revert r9167
``docutils.core.publish_string`` uses Python 2 notion of a bytestring, such that in the general case it returns Python 3's ``bytes`` type. Revision 9167 attempted to address this distinction by introducing ``publish_bytes`` and changing ``publish_string`` to always return unicode text data as Python's ``str`` type. This is a backwards compatibility break, so in this commit we restore the previous behaviour, whilst simultaneously deprecating support for returning binary data from the ``docutils.core.publish_string`` function for at least two releases of Docutils. As part of this, we also deprecate returning binary data from the ``docutils.io.StringOutput.encode`` method, docutils.io.BytesOutput`` should be used in its stead. Finally, we update tests for the reversion to the previous behaviour. git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@9202 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/writers/docutils_xml.py')
-rw-r--r--docutils/writers/docutils_xml.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py
index b57a61d3e..b1fe841c7 100644
--- a/docutils/writers/docutils_xml.py
+++ b/docutils/writers/docutils_xml.py
@@ -101,7 +101,7 @@ class XMLTranslator(nodes.GenericNodeVisitor):
self.output = []
if settings.xml_declaration:
self.output.append(
- self.xml_declaration % settings.output_encoding)
+ self.xml_declaration % _output_encoding(settings))
if settings.doctype_declaration:
self.output.append(self.doctype)
self.output.append(self.generator % docutils.__version__)
@@ -186,3 +186,10 @@ class TestXml(xml.sax.handler.ContentHandler):
def setDocumentLocator(self, locator):
self.locator = locator
+
+
+def _output_encoding(settings):
+ """TEMPORARY, remove in Docutils 0.21"""
+ if settings.output_encoding == 'unicode':
+ return 'utf-8'
+ return settings.output_encoding