Commit d1ab2651 authored by Eli Bendersky's avatar Eli Bendersky

Replace the iter/itertext methods of Element in _elementtree with true C...

Replace the iter/itertext methods of Element in _elementtree with true C implementations, instead of the bootstrapped Python code. In addition to being cleaner (removing the last remains of the bootstrapping code in _elementtree), this gives a 10x performance boost for iter() on large documents.
Also reorganized the tests a bit to be more robust.
parent d4fdbef3
This diff is collapsed.
...@@ -8,31 +8,6 @@ cET = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree']) ...@@ -8,31 +8,6 @@ cET = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree'])
cET_alias = import_fresh_module('xml.etree.cElementTree', fresh=['_elementtree', 'xml.etree']) cET_alias = import_fresh_module('xml.etree.cElementTree', fresh=['_elementtree', 'xml.etree'])
# cElementTree specific tests
def sanity():
r"""
Import sanity.
Issue #6697.
>>> cElementTree = cET
>>> e = cElementTree.Element('a')
>>> getattr(e, '\uD800') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
UnicodeEncodeError: ...
>>> p = cElementTree.XMLParser()
>>> p.version.split()[0]
'Expat'
>>> getattr(p, '\uD800')
Traceback (most recent call last):
...
AttributeError: 'XMLParser' object has no attribute '\ud800'
"""
class MiscTests(unittest.TestCase): class MiscTests(unittest.TestCase):
# Issue #8651. # Issue #8651.
@support.bigmemtest(size=support._2G + 100, memuse=1) @support.bigmemtest(size=support._2G + 100, memuse=1)
...@@ -46,6 +21,7 @@ class MiscTests(unittest.TestCase): ...@@ -46,6 +21,7 @@ class MiscTests(unittest.TestCase):
finally: finally:
data = None data = None
@unittest.skipUnless(cET, 'requires _elementtree') @unittest.skipUnless(cET, 'requires _elementtree')
class TestAliasWorking(unittest.TestCase): class TestAliasWorking(unittest.TestCase):
# Test that the cET alias module is alive # Test that the cET alias module is alive
...@@ -53,6 +29,7 @@ class TestAliasWorking(unittest.TestCase): ...@@ -53,6 +29,7 @@ class TestAliasWorking(unittest.TestCase):
e = cET_alias.Element('foo') e = cET_alias.Element('foo')
self.assertEqual(e.tag, 'foo') self.assertEqual(e.tag, 'foo')
@unittest.skipUnless(cET, 'requires _elementtree') @unittest.skipUnless(cET, 'requires _elementtree')
class TestAcceleratorImported(unittest.TestCase): class TestAcceleratorImported(unittest.TestCase):
# Test that the C accelerator was imported, as expected # Test that the C accelerator was imported, as expected
...@@ -67,7 +44,6 @@ def test_main(): ...@@ -67,7 +44,6 @@ def test_main():
from test import test_xml_etree, test_xml_etree_c from test import test_xml_etree, test_xml_etree_c
# Run the tests specific to the C implementation # Run the tests specific to the C implementation
support.run_doctest(test_xml_etree_c, verbosity=True)
support.run_unittest( support.run_unittest(
MiscTests, MiscTests,
TestAliasWorking, TestAliasWorking,
......
...@@ -916,11 +916,7 @@ def _namespaces(elem, default_namespace=None): ...@@ -916,11 +916,7 @@ def _namespaces(elem, default_namespace=None):
_raise_serialization_error(qname) _raise_serialization_error(qname)
# populate qname and namespaces table # populate qname and namespaces table
try: for elem in elem.iter():
iterate = elem.iter
except AttributeError:
iterate = elem.getiterator # cET compatibility
for elem in iterate():
tag = elem.tag tag = elem.tag
if isinstance(tag, QName): if isinstance(tag, QName):
if tag.text not in qnames: if tag.text not in qnames:
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment