mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
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
This commit is contained in:
parent
fb625448f8
commit
46955b2d30
2 changed files with 7 additions and 19 deletions
|
|
@ -1983,7 +1983,7 @@ def test_element_factory_pure_python_subclass(self):
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -246,7 +246,6 @@ def extend(self, elements):
|
|||
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 @@ def insert(self, index, subelement):
|
|||
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 @@ def getchildren(self):
|
|||
)
|
||||
return self._children
|
||||
|
||||
|
||||
def find(self, path, namespaces=None):
|
||||
"""Find first matching element by tag name or path.
|
||||
|
||||
|
|
@ -299,7 +296,6 @@ def find(self, path, namespaces=None):
|
|||
"""
|
||||
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 @@ def findtext(self, path, default=None, namespaces=None):
|
|||
"""
|
||||
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 @@ def findall(self, path, namespaces=None):
|
|||
"""
|
||||
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 @@ def iterfind(self, path, namespaces=None):
|
|||
"""
|
||||
return ElementPath.iterfind(self, path, namespaces)
|
||||
|
||||
|
||||
def clear(self):
|
||||
"""Reset element.
|
||||
|
||||
|
|
@ -350,7 +343,6 @@ def clear(self):
|
|||
self._children = []
|
||||
self.text = self.tail = None
|
||||
|
||||
|
||||
def get(self, key, default=None):
|
||||
"""Get element attribute.
|
||||
|
||||
|
|
@ -364,7 +356,6 @@ def get(self, key, default=None):
|
|||
"""
|
||||
return self.attrib.get(key, default)
|
||||
|
||||
|
||||
def set(self, key, value):
|
||||
"""Set element attribute.
|
||||
|
||||
|
|
@ -375,7 +366,6 @@ def set(self, key, value):
|
|||
"""
|
||||
self.attrib[key] = value
|
||||
|
||||
|
||||
def keys(self):
|
||||
"""Get list of attribute names.
|
||||
|
||||
|
|
@ -385,7 +375,6 @@ def keys(self):
|
|||
"""
|
||||
return self.attrib.keys()
|
||||
|
||||
|
||||
def items(self):
|
||||
"""Get element attributes as a sequence.
|
||||
|
||||
|
|
@ -397,7 +386,6 @@ def items(self):
|
|||
"""
|
||||
return self.attrib.items()
|
||||
|
||||
|
||||
def iter(self, tag=None):
|
||||
"""Create tree iterator.
|
||||
|
||||
|
|
@ -430,7 +418,6 @@ def getiterator(self, tag=None):
|
|||
)
|
||||
return list(self.iter(tag))
|
||||
|
||||
|
||||
def itertext(self):
|
||||
"""Create text iterator.
|
||||
|
||||
|
|
@ -448,9 +435,6 @@ def itertext(self):
|
|||
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 @@ def close(self):
|
|||
|
||||
# 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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue