[Python-checkins] cpython (2.7): Issue #18347: ElementTree's html serializer now preserves the case of closing

christian.heimes python-checkins at python.org
Fri Jul 5 01:41:53 CEST 2013


http://hg.python.org/cpython/rev/328781ae35d2
changeset:   84451:328781ae35d2
branch:      2.7
parent:      84441:e3fd5fc5dc47
user:        Christian Heimes <christian at cheimes.de>
date:        Fri Jul 05 01:41:30 2013 +0200
summary:
  Issue #18347: ElementTree's html serializer now preserves the case of closing tags.

files:
  Lib/test/test_xml_etree.py   |  10 ++++++++++
  Lib/xml/etree/ElementTree.py |   6 +++---
  Misc/NEWS                    |   3 +++
  3 files changed, 16 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1769,6 +1769,16 @@
 
     """
 
+def bug_18347():
+    """
+
+    >>> e = ET.XML('<html><CamelCase>text</CamelCase></html>')
+    >>> serialize(e)
+    '<html><CamelCase>text</CamelCase></html>'
+    >>> serialize(e, method="html")
+    '<html><CamelCase>text</CamelCase></html>'
+    """
+
 # --------------------------------------------------------------------
 # reported on bugs.python.org
 
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -988,15 +988,15 @@
                     # FIXME: handle boolean attributes
                     write(" %s=\"%s\"" % (qnames[k], v))
             write(">")
-            tag = tag.lower()
+            ltag = tag.lower()
             if text:
-                if tag == "script" or tag == "style":
+                if ltag == "script" or ltag == "style":
                     write(_encode(text, encoding))
                 else:
                     write(_escape_cdata(text, encoding))
             for e in elem:
                 _serialize_html(write, e, encoding, qnames, None)
-            if tag not in HTML_EMPTY:
+            if ltag not in HTML_EMPTY:
                 write("</" + tag + ">")
     if elem.tail:
         write(_escape_cdata(elem.tail, encoding))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@
 Library
 -------
 
+- Issue #18347: ElementTree's html serializer now preserves the case of
+  closing tags.
+
 - Issue #17261: Ensure multiprocessing's proxies use proper address.
 
 - Issue #17097: Make multiprocessing ignore EINTR.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list