diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-05-19 16:20:50 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-05-19 16:20:50 (GMT) |
commit | 46955b2d30c0185d6471ce42c7766633b499e232 (patch) | |
tree | e797823d1408fc6a5257b4b065d6f85705beb855 | |
parent | fb625448f83036b24b3191b8c2a062362bf8ad26 (diff) | |
download | cpython-46955b2d30c0185d6471ce42c7766633b499e232.zip cpython-46955b2d30c0185d6471ce42c7766633b499e232.tar.gz cpython-46955b2d30c0185d6471ce42c7766633b499e232.tar.bz2 |
Issue #17988: remove unused alias for Element and rename the used one
Renaming to _Element_Py for clarity and moving it to a more logical location.
_ElementInterface OTOH is unused and is therefore removed.
Close #17988
-rw-r--r-- | Lib/test/test_xml_etree.py | 2 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 24 |
2 files changed, 7 insertions, 19 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 6973371..2636da3 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1983,7 +1983,7 @@ class TreeBuilderTest(unittest.TestCase): # Mimick SimpleTAL's behaviour (issue #16089): both versions of # TreeBuilder should be able to cope with a subclass of the # pure Python Element class. - base = ET._Element + base = ET._Element_Py # Not from a C extension self.assertEqual(base.__module__, 'xml.etree.ElementTree') # Force some multiple inheritance with a C class to make things diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 1ab80cd..e0b4fd4 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -246,7 +246,6 @@ class Element: self._assert_is_element(element) self._children.extend(elements) - def insert(self, index, subelement): """Insert *subelement* at position *index*.""" self._assert_is_element(subelement) @@ -255,10 +254,9 @@ class Element: def _assert_is_element(self, e): # Need to refer to the actual Python implementation, not the # shadowing C implementation. - if not isinstance(e, _Element): + if not isinstance(e, _Element_Py): raise TypeError('expected an Element, not %s' % type(e).__name__) - def remove(self, subelement): """Remove matching subelement. @@ -287,7 +285,6 @@ class Element: ) return self._children - def find(self, path, namespaces=None): """Find first matching element by tag name or path. @@ -299,7 +296,6 @@ class Element: """ return ElementPath.find(self, path, namespaces) - def findtext(self, path, default=None, namespaces=None): """Find text for first matching element by tag name or path. @@ -314,7 +310,6 @@ class Element: """ return ElementPath.findtext(self, path, default, namespaces) - def findall(self, path, namespaces=None): """Find all matching subelements by tag name or path. @@ -326,7 +321,6 @@ class Element: """ return ElementPath.findall(self, path, namespaces) - def iterfind(self, path, namespaces=None): """Find all matching subelements by tag name or path. @@ -338,7 +332,6 @@ class Element: """ return ElementPath.iterfind(self, path, namespaces) - def clear(self): """Reset element. @@ -350,7 +343,6 @@ class Element: self._children = [] self.text = self.tail = None - def get(self, key, default=None): """Get element attribute. @@ -364,7 +356,6 @@ class Element: """ return self.attrib.get(key, default) - def set(self, key, value): """Set element attribute. @@ -375,7 +366,6 @@ class Element: """ self.attrib[key] = value - def keys(self): """Get list of attribute names. @@ -385,7 +375,6 @@ class Element: """ return self.attrib.keys() - def items(self): """Get element attributes as a sequence. @@ -397,7 +386,6 @@ class Element: """ return self.attrib.items() - def iter(self, tag=None): """Create tree iterator. @@ -430,7 +418,6 @@ class Element: ) return list(self.iter(tag)) - def itertext(self): """Create text iterator. @@ -448,9 +435,6 @@ class Element: if e.tail: yield e.tail -# compatibility -_Element = _ElementInterface = Element - def SubElement(parent, tag, attrib={}, **extra): """Subelement factory which creates an element instance, and appends it @@ -1663,13 +1647,17 @@ class XMLParser: # Import the C accelerators try: + # Element is going to be shadowed by the C implementation. We need to keep + # the Python version of it accessible for some "creative" by external code + # (see tests) + _Element_Py = Element + # Element, SubElement, ParseError, TreeBuilder, XMLParser from _elementtree import * except ImportError: pass else: # Overwrite 'ElementTree.parse' to use the C XMLParser - class ElementTree(ElementTree): __doc__ = ElementTree.__doc__ def parse(self, source, parser=None): |