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

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


http://hg.python.org/cpython/rev/d5536c06a082
changeset:   84450:d5536c06a082
parent:      84448:de947db308ba
parent:      84449:df79735b21c1
user:        Christian Heimes <christian at cheimes.de>
date:        Fri Jul 05 01:40:52 2013 +0200
summary:
  Issue #18347: ElementTree's html serializer now preserves the case of closing tags.

files:
  Lib/test/test_xml_etree.py   |  7 +++++++
  Lib/xml/etree/ElementTree.py |  6 +++---
  Misc/NEWS                    |  3 +++
  3 files changed, 13 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
@@ -742,6 +742,13 @@
                 '<html><link><script>1 < 2</script></html>\n')
         self.assertEqual(serialize(e, method="text"), '1 < 2\n')
 
+    def test_issue18347(self):
+        e = ET.XML('<html><CamelCase>text</CamelCase></html>')
+        self.assertEqual(serialize(e),
+                '<html><CamelCase>text</CamelCase></html>')
+        self.assertEqual(serialize(e, method="html"),
+                '<html><CamelCase>text</CamelCase></html>')
+
     def test_entity(self):
         # Test entity handling.
 
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
@@ -992,15 +992,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(text)
                 else:
                     write(_escape_cdata(text))
             for e in elem:
                 _serialize_html(write, e, qnames, None)
-            if tag not in HTML_EMPTY:
+            if ltag not in HTML_EMPTY:
                 write("</" + tag + ">")
     if elem.tail:
         write(_escape_cdata(elem.tail))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -135,6 +135,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 #18343: faulthandler.register() now keeps the previous signal handler

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


More information about the Python-checkins mailing list