Skip to content

Commit 06faed8

Browse files
committed
Clean up getTreeBuilder, remove dom.TreeBuilder from 0.10 legacy.
1 parent 54648ef commit 06faed8

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

CHANGES.rst

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Released on XXX, 2013
2626
* Removed the ``XHTMLSerializer`` as it never actually guaranteed its
2727
output was well-formed XML, and hence provided little of use.
2828

29+
* Removed default DOM treebuilder, so ``html5lib.treebuilders.dom`` is no
30+
longer supported. ``html5lib.treebuilders.getTreeBuilder("dom")`` will
31+
return the default DOM treebuilder, which uses ``xml.dom.minidom``.
32+
2933
* Optional heuristic character encoding detection now based on
3034
``charade`` for Python 2.6 - 3.3 compatibility.
3135

html5lib/treebuilders/__init__.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -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 or lxml.etree."""
51+
xml.etree.ElementTree or xml.etree.cElementTree."""
5152

5253
treeType = treeType.lower()
5354
if treeType not in treeBuilderCache:
5455
if treeType == "dom":
5556
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)
5758
if implementation is None:
5859
from xml.dom import minidom
5960
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
6162
return dom.getDomModule(implementation, **kwargs).TreeBuilder
6263
elif treeType == "lxml":
6364
from . import etree_lxml
6465
treeBuilderCache[treeType] = etree_lxml.TreeBuilder
6566
elif treeType == "etree":
66-
# Come up with a sane default
67+
# Come up with a sane default (pref. from the stdlib)
6768
if implementation is None:
6869
try:
6970
import xml.etree.cElementTree as ET
7071
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
7873
implementation = ET
7974
from . import etree
8075
# NEVER cache here, caching is done in the etree submodule

html5lib/treebuilders/dom.py

-6
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,3 @@ def dom2sax(node, handler, nsmap={'xml': XML_NAMESPACE}):
288288

289289
# The actual means to get a module!
290290
getDomModule = moduleFactoryFactory(getDomBuilder)
291-
292-
293-
# Keep backwards compatibility with things that directly load
294-
# classes/functions from this module
295-
for key, value in list(getDomModule(minidom).__dict__.items()):
296-
globals()[key] = value

0 commit comments

Comments
 (0)