Jacques Frechet's and John Reese's simplification of ElementTree: give up

attempts at backwards compatibility which can't work anyway on Py3k (and aren't
needed for Python 2.5 and later).
This commit is contained in:
Alex Martelli 2006-08-21 23:45:19 +00:00
parent 0008602188
commit 6cefeb0e81
1 changed files with 1 additions and 27 deletions

View File

@ -111,33 +111,7 @@ __all__ = [
import string, sys, re import string, sys, re
class _SimpleElementPath: from . import ElementPath
# emulate pre-1.2 find/findtext/findall behaviour
def find(self, element, tag):
for elem in element:
if elem.tag == tag:
return elem
return None
def findtext(self, element, tag, default=None):
for elem in element:
if elem.tag == tag:
return elem.text or ""
return default
def findall(self, element, tag):
if tag[:3] == ".//":
return element.getiterator(tag[3:])
result = []
for elem in element:
if elem.tag == tag:
result.append(elem)
return result
try:
from . import ElementPath
except ImportError:
# FIXME: issue warning in this case?
# TODO: DEFINITELY issue warning here!!!
ElementPath = _SimpleElementPath()
# TODO: add support for custom namespace resolvers/default namespaces # TODO: add support for custom namespace resolvers/default namespaces
# TODO: add improved support for incremental parsing # TODO: add improved support for incremental parsing