@@ -37,44 +37,39 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
37
37
treeType - the name of the tree type required (case-insensitive). Supported
38
38
values are:
39
39
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.
47
48
48
49
implementation - (Currently applies to the "etree" and "dom" tree types). A
49
50
module implementing the tree type e.g.
50
- xml.etree.ElementTree or lxml .etree."""
51
+ xml.etree.ElementTree or xml .etree.cElementTree ."""
51
52
52
53
treeType = treeType .lower ()
53
54
if treeType not in treeBuilderCache :
54
55
if treeType == "dom" :
55
56
from . 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)
57
58
if implementation is None :
58
59
from xml .dom import minidom
59
60
implementation = minidom
60
- # XXX: NEVER cache here, caching is done in the dom submodule
61
+ # NEVER cache here, caching is done in the dom submodule
61
62
return dom .getDomModule (implementation , ** kwargs ).TreeBuilder
62
63
elif treeType == "lxml" :
63
64
from . import etree_lxml
64
65
treeBuilderCache [treeType ] = etree_lxml .TreeBuilder
65
66
elif treeType == "etree" :
66
- # Come up with a sane default
67
+ # Come up with a sane default (pref. from the stdlib)
67
68
if implementation is None :
68
69
try :
69
70
import xml .etree .cElementTree as ET
70
71
except 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
78
73
implementation = ET
79
74
from . import etree
80
75
# NEVER cache here, caching is done in the etree submodule
0 commit comments