@@ -37,44 +37,39 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
3737 treeType - the name of the tree type required (case-insensitive). Supported
3838 values are:
3939
40- "dom" - A generic builder for DOM implementations, defaulting to
41- a xml.dom.minidom based implementation for the sake of
42- backwards compatibility (as releases up until 0.10 had a
43- builder called "dom" that was a minidom implemenation).
44- "etree" - A generic builder for tree implementations exposing an
45- elementtree-like interface (known to work with
46- ElementTree, cElementTree and lxml.etree).
40+ "dom" - A generic builder for DOM implementations, defaulting to
41+ a xml.dom.minidom based implementation.
42+ "etree" - A generic builder for tree implementations exposing an
43+ ElementTree-like interface, defaulting to
44+ xml.etree.cElementTree if available and
45+ xml.etree.ElementTree if not.
46+ "lxml" - A etree-based builder for lxml.etree, handling
47+ limitations of lxml's implementation.
4748
4849 implementation - (Currently applies to the "etree" and "dom" tree types). A
4950 module implementing the tree type e.g.
50- xml.etree.ElementTree orlxml .etree."""
51+ xml.etree.ElementTree orxml .etree.cElementTree ."""
5152
5253treeType = treeType .lower ()
5354if treeType not in treeBuilderCache :
5455if treeType == "dom" :
5556from .import dom
56- #XXX: Keep backwards compatibility by using minidom if no implementation is given
57+ #Come up with a sane default (pref. from the stdlib)
5758if implementation is None :
5859from xml .dom import minidom
5960implementation = minidom
60- #XXX: NEVER cache here, caching is done in the dom submodule
61+ # NEVER cache here, caching is done in the dom submodule
6162return dom .getDomModule (implementation ,** kwargs ).TreeBuilder
6263elif treeType == "lxml" :
6364from .import etree_lxml
6465treeBuilderCache [treeType ]= etree_lxml .TreeBuilder
6566elif treeType == "etree" :
66- # Come up with a sane default
67+ # Come up with a sane default (pref. from the stdlib)
6768if implementation is None :
6869try :
6970import xml .etree .cElementTree as ET
7071except ImportError :
71- try :
72- import xml .etree .ElementTree as ET
73- except ImportError :
74- try :
75- import cElementTree as ET
76- except ImportError :
77- import elementtree .ElementTree as ET
72+ import xml .etree .ElementTree as ET
7873implementation = ET
7974from .import etree
8075# NEVER cache here, caching is done in the etree submodule