Skip to content

Commit a4fc4d8

Browse files
committed
Move default_etree to utils.py and use it for the treewalker too.
1 parent 6c54f20 commit a4fc4d8

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

html5lib/treebuilders/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
from __future__ import absolute_import, division, unicode_literals
3030

31+
from ..utils import default_etree
32+
3133
treeBuilderCache = {}
3234

3335

@@ -64,14 +66,9 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
6466
from . import etree_lxml
6567
treeBuilderCache[treeType] = etree_lxml.TreeBuilder
6668
elif treeType == "etree":
67-
# Come up with a sane default (pref. from the stdlib)
68-
if implementation is None:
69-
try:
70-
import xml.etree.cElementTree as ET
71-
except ImportError:
72-
import xml.etree.ElementTree as ET
73-
implementation = ET
7469
from . import etree
70+
if implementation is None:
71+
implementation = default_etree
7572
# NEVER cache here, caching is done in the etree submodule
7673
return etree.getETreeModule(implementation, **kwargs).TreeBuilder
7774
else:

html5lib/treewalkers/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import sys
1414

15+
from ..utils import default_etree
16+
1517
treeWalkerCache = {}
1618

1719

@@ -48,6 +50,8 @@ def getTreeWalker(treeType, implementation=None, **kwargs):
4850
treeWalkerCache[treeType] = lxmletree.TreeWalker
4951
elif treeType == "etree":
5052
from . import etree
53+
if implementation is None:
54+
implementation = default_etree
5155
# XXX: NEVER cache here, caching is done in the etree submodule
5256
return etree.getETreeModule(implementation, **kwargs).TreeWalker
5357
return treeWalkerCache.get(treeType)

html5lib/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
from types import ModuleType
44

5+
try:
6+
import xml.etree.cElementTree as default_etree
7+
except ImportError:
8+
import xml.etree.ElementTree as default_etree
9+
510

611
class MethodDispatcher(dict):
712
"""Dict with 2 special properties:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy