summaryrefslogtreecommitdiff
path: root/Lib/xml/etree
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-05-19 09:20:50 -0700
committerEli Bendersky <eliben@gmail.com>2013-05-19 09:20:50 -0700
commit236ff9507991910ea6a9eb41ca85bad41344f38d (patch)
tree228d8d60370e3743dd377fbda401ec3254c3a818 /Lib/xml/etree
parent70f61ef48707ddc6e9899575074029db15e68257 (diff)
downloadcpython-236ff9507991910ea6a9eb41ca85bad41344f38d.tar.gz
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
Diffstat (limited to 'Lib/xml/etree')
-rw-r--r--Lib/xml/etree/ElementTree.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 1ab80cdcdd..e0b4fd40fa 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):