[Python-checkins] r78126 - in python/branches/py3k: Lib/test/test_xml_etree.py Lib/xml/etree/ElementTree.py Misc/ACKS Misc/NEWS

antoine.pitrou python-checkins at python.org
Tue Feb 9 18:25:47 CET 2010


Author: antoine.pitrou
Date: Tue Feb  9 18:25:47 2010
New Revision: 78126

Log:
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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_xml_etree.py
   python/branches/py3k/Lib/xml/etree/ElementTree.py
   python/branches/py3k/Misc/ACKS
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/test_xml_etree.py
==============================================================================
--- python/branches/py3k/Lib/test/test_xml_etree.py	(original)
+++ python/branches/py3k/Lib/test/test_xml_etree.py	Tue Feb  9 18:25:47 2010
@@ -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

Modified: python/branches/py3k/Lib/xml/etree/ElementTree.py
==============================================================================
--- python/branches/py3k/Lib/xml/etree/ElementTree.py	(original)
+++ python/branches/py3k/Lib/xml/etree/ElementTree.py	Tue Feb  9 18:25:47 2010
@@ -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

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Tue Feb  9 18:25:47 2010
@@ -529,6 +529,7 @@
 Sjoerd Mullender
 Sape Mullender
 Michael Muller
+Neil Muller
 R. David Murray
 Piotr Meyer
 John Nagle

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Feb  9 18:25:47 2010
@@ -242,6 +242,11 @@
 Library
 -------
 
+- 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.
+
 - Issue #6233: ElementTree failed converting unicode characters to XML
   entities when they could't be represented in the requested output
   encoding.  Patch by Jerry Chen.


More information about the Python-checkins mailing list