Merged revisions 78125 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78125 | antoine.pitrou | 2010-02-09 18:08:05 +0100 (mar., 09 févr. 2010) | 7 lines

  Issue #2746: Don't escape ampersands and angle brackets ("&", "<", ">")
  in XML processing instructions and comments.  These raw characters are
  allowed by the XML specification, and are necessary when outputting e.g.
  PHP code in a processing instruction.  Patch by Neil Muller.
........
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index a7ad48b..3df1896 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -210,6 +210,26 @@
     """
     ET.XML("<?xml version='1.0' encoding='%s'?><xml />" % encoding)
 
+def processinginstruction():
+    r"""
+    Test ProcessingInstruction directly
+
+    >>> from xml.etree import ElementTree as ET
+
+    >>> ET.tostring(ET.ProcessingInstruction('test', 'instruction'))
+    '<?test instruction?>'
+    >>> ET.tostring(ET.PI('test', 'instruction'))
+    '<?test instruction?>'
+
+    Issue #2746
+
+    >>> ET.tostring(ET.PI('test', '<testing&>'))
+    '<?test <testing&>?>'
+    >>> ET.tostring(ET.PI('test', '<testing&>\xe3'), 'latin1')
+    b"<?xml version='1.0' encoding='latin1'?>\n<?test <testing&>\xe3?>"
+
+    """
+
 def check_issue6233():
     """
     >>> from xml.etree import ElementTree as ET
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index c47573e..2663b33 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -662,9 +662,9 @@
         # write XML to file
         tag = node.tag
         if tag is Comment:
-            file.write(b"<!-- " + _encode_cdata(node.text, encoding) + b" -->")
+            file.write(_encode("<!-- %s -->" % node.text, encoding))
         elif tag is ProcessingInstruction:
-            file.write(b"<?" + _encode_cdata(node.text, encoding) + b"?>")
+            file.write(_encode("<?%s?>" % node.text, encoding))
         else:
             items = list(node.items())
             xmlns_items = [] # new namespaces in this scope