bpo-36543: Revert "bpo-36543: Remove the xml.etree.cElementTree module." (GH-20117)
* Revert "bpo-36543: Remove the xml.etree.cElementTree module. (GH-19108)"
This reverts commit b33e52511a59c6da7132c226b7f7489b092a33eb.
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
index 7437e13..e26e171 100644
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -8,6 +8,9 @@
cET = import_fresh_module('xml.etree.ElementTree',
fresh=['_elementtree'])
+cET_alias = import_fresh_module('xml.etree.cElementTree',
+ fresh=['_elementtree', 'xml.etree'],
+ deprecated=True)
@unittest.skipUnless(cET, 'requires _elementtree')
@@ -168,6 +171,14 @@
@unittest.skipUnless(cET, 'requires _elementtree')
+class TestAliasWorking(unittest.TestCase):
+ # Test that the cET alias module is alive
+ def test_alias_working(self):
+ e = cET_alias.Element('foo')
+ self.assertEqual(e.tag, 'foo')
+
+
+@unittest.skipUnless(cET, 'requires _elementtree')
@support.cpython_only
class TestAcceleratorImported(unittest.TestCase):
# Test that the C accelerator was imported, as expected
@@ -175,6 +186,9 @@
# SubElement is a function so it retains _elementtree as its module.
self.assertEqual(cET.SubElement.__module__, '_elementtree')
+ def test_correct_import_cET_alias(self):
+ self.assertEqual(cET_alias.SubElement.__module__, '_elementtree')
+
def test_parser_comes_from_C(self):
# The type of methods defined in Python code is types.FunctionType,
# while the type of methods defined inside _elementtree is
@@ -214,6 +228,7 @@
# Run the tests specific to the C implementation
support.run_unittest(
MiscTests,
+ TestAliasWorking,
TestAcceleratorImported,
SizeofTest,
)
diff --git a/Lib/xml/etree/cElementTree.py b/Lib/xml/etree/cElementTree.py
new file mode 100644
index 0000000..368e679
--- /dev/null
+++ b/Lib/xml/etree/cElementTree.py
@@ -0,0 +1,3 @@
+# Deprecated alias for xml.etree.ElementTree
+
+from xml.etree.ElementTree import *