Skip to content

Commit 951dc02

Browse files
author
Mark Pilgrim
committed
various fixes to make lxml treebuilder actually work in python 3
1 parent 9dc584c commit 951dc02

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/html5lib/treebuilders/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
6767
from . import simpletree
6868
treeBuilderCache[treeType] = simpletree.TreeBuilder
6969
elif treeType == "beautifulsoup":
70-
import soup
70+
from . import soup
7171
treeBuilderCache[treeType] = soup.TreeBuilder
7272
elif treeType == "lxml":
73-
import etree_lxml
73+
from . import etree_lxml
7474
treeBuilderCache[treeType] = etree_lxml.TreeBuilder
7575
elif treeType == "etree":
7676
if implementation is None:

src/html5lib/treebuilders/etree_lxml.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import _base
2-
import new
1+
from . import _base
32
import warnings
4-
from html5lib.constants import DataLossWarning
5-
import etree as etree_builders
6-
from html5lib import ihatexml
3+
from ..constants import DataLossWarning
4+
from . import etree as etree_builders
5+
from .. import ihatexml
76

87
try:
98
import lxml.etree as etree
@@ -158,7 +157,7 @@ class Attributes(dict):
158157
def __init__(self, element, value={}):
159158
self._element = element
160159
dict.__init__(self, value)
161-
for k, v in self.iteritems():
160+
for k, v in self.items():
162161
self._element._element.attrib[filter.coerceAttribute(k)] = v
163162

164163
def __setitem__(self, key, value):
@@ -263,7 +262,7 @@ def insertRoot(self, token):
263262
"""Create the document root"""
264263
#Because of the way libxml2 works, it doesn't seem to be possible to
265264
#alter information like the doctype after the tree has been parsed.
266-
#Therefore we need to use the built-in parser to create our iniial
265+
#Therefore we need to use the built-in parser to create our initial
267266
#tree, after which we can add elements like normal
268267
docStr = ""
269268
if self.doctype and self.doctype.name:
@@ -278,7 +277,7 @@ def insertRoot(self, token):
278277
try:
279278
root = etree.fromstring(docStr)
280279
except etree.XMLSyntaxError:
281-
print docStr
280+
print(docStr)
282281
raise
283282

284283
#Append the initial comments:

0 commit comments

Comments
 (0)