Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8755eb6

Browse files
committed
Extend getTreeBuilder()'s second argument (implementation) to the "dom" treebuilder type. Should be fully backwards compatible. Currently only tested with minidom, though.
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401098
1 parent4bf7e88 commit8755eb6

File tree

2 files changed

+230
-197
lines changed

2 files changed

+230
-197
lines changed

‎src/html5lib/treebuilders/__init__.py‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,32 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
4040
4141
"simpletree" - a built-in DOM-ish tree type with support for some
4242
more pythonic idioms.
43-
"dom" - The xml.dom.minidom DOM implementation
43+
"dom" - A generic builder for DOM implementations, defaulting to
44+
a xml.dom.minidom based implementation for the sake of
45+
backwards compatibility (as releases up until 0.10 had a
46+
builder called "dom" that was a minidom implemenation).
4447
"etree" - A generic builder for tree implementations exposing an
4548
elementtree-like interface (known to work with
4649
ElementTree, cElementTree and lxml.etree).
4750
"beautifulsoup" - Beautiful soup (if installed)
4851
49-
implementation - (Currently applies to the "etree"tree type only). A module
50-
implementing the tree type e.g. xml.etree.ElementTree or
51-
lxml.etree."""
52+
implementation - (Currently applies to the "etree"and "dom" tree types). A
53+
moduleimplementing the tree type e.g.
54+
xml.etree.ElementTree orlxml.etree."""
5255

5356
treeType=treeType.lower()
5457
iftreeTypenotintreeBuilderCache:
55-
iftreeTypein ("dom","simpletree"):
56-
mod=__import__(treeType,globals())
57-
treeBuilderCache[treeType]=mod.TreeBuilder
58+
iftreeType=="dom":
59+
importdom
60+
# XXX: Keep backwards compatibility by using minidom if no implementation is given
61+
ifimplementation==None:
62+
fromxml.domimportminidom
63+
implementation=minidom
64+
# XXX: NEVER cache here, caching is done in the dom submodule
65+
returndom.getDomModule(implementation,**kwargs).TreeBuilder
66+
eliftreeType=="simpletree":
67+
importsimpletree
68+
treeBuilderCache[treeType]=simpletree.TreeBuilder
5869
eliftreeType=="beautifulsoup":
5970
importsoup
6071
treeBuilderCache[treeType]=soup.TreeBuilder

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp