[Python-checkins] cpython: Issue #17988: remove unused alias for Element and rename the used one
eli.bendersky
python-checkins at python.org
Sun May 19 18:21:02 CEST 2013
http://hg.python.org/cpython/rev/16a03959819a
changeset: 83845:16a03959819a
user: Eli Bendersky <eliben at gmail.com>
date: Sun May 19 09:20:50 2013 -0700
summary:
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
files:
Lib/test/test_xml_etree.py | 2 +-
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
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1983,7 +1983,7 @@
# 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
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -246,7 +246,6 @@
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 _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 @@
)
return self._children
-
def find(self, path, namespaces=None):
"""Find first matching element by tag name or path.
@@ -299,7 +296,6 @@
"""
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 @@
"""
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 @@
"""
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 @@
"""
return ElementPath.iterfind(self, path, namespaces)
-
def clear(self):
"""Reset element.
@@ -350,7 +343,6 @@
self._children = []
self.text = self.tail = None
-
def get(self, key, default=None):
"""Get element attribute.
@@ -364,7 +356,6 @@
"""
return self.attrib.get(key, default)
-
def set(self, key, value):
"""Set element attribute.
@@ -375,7 +366,6 @@
"""
self.attrib[key] = value
-
def keys(self):
"""Get list of attribute names.
@@ -385,7 +375,6 @@
"""
return self.attrib.keys()
-
def items(self):
"""Get element attributes as a sequence.
@@ -397,7 +386,6 @@
"""
return self.attrib.items()
-
def iter(self, tag=None):
"""Create tree iterator.
@@ -430,7 +418,6 @@
)
return list(self.iter(tag))
-
def itertext(self):
"""Create text iterator.
@@ -448,9 +435,6 @@
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 @@
# 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):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list