Index: Lib/test/test_xml_etree.py
===================================================================
--- Lib/test/test_xml_etree.py (revision 73267)
+++ Lib/test/test_xml_etree.py (working copy)
@@ -213,8 +213,25 @@
>>> check_encoding(ET, "mac-roman")
"""
ET.XML("" % encoding)
+
+def processinginstruction():
+ """
+ Test ProcessingInstruction directly
+ >>> from xml.etree import ElementTree as ET
+ >>> ET.tostring(ET.ProcessingInstruction('test', 'instruction'))
+ ''
+ >>> ET.tostring(ET.PI('test', 'instruction'))
+ ''
+
+ Issue #2746
+
+ >>> ET.tostring(ET.PI('test', ''))
+ '?>'
+
+ """
+
#
# xinclude tests (samples from appendix C of the xinclude specification)
Index: Lib/xml/etree/ElementTree.py
===================================================================
--- Lib/xml/etree/ElementTree.py (revision 73267)
+++ Lib/xml/etree/ElementTree.py (working copy)
@@ -666,9 +666,9 @@
# write XML to file
tag = node.tag
if tag is Comment:
- file.write("" % _escape_cdata(node.text, encoding))
+ file.write("" % _encode(node.text, encoding))
elif tag is ProcessingInstruction:
- file.write("%s?>" % _escape_cdata(node.text, encoding))
+ file.write("%s?>" % _encode(node.text, encoding))
else:
items = node.items()
xmlns_items = [] # new namespaces in this scope