Permalink
Browse files

various fixes to make lxml treebuilder actually work in python 3

  • Loading branch information...
1 parent bf33434 commit dbcb5fcec16e5238d8813c9b9a614342ee280789 Mark Pilgrim committed Oct 7, 2009
Showing with 9 additions and 10 deletions.
  1. +2 −2 src/html5lib/treebuilders/__init__.py
  2. +7 −8 src/html5lib/treebuilders/etree_lxml.py
View
4 src/html5lib/treebuilders/__init__.py
@@ -67,10 +67,10 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
from . import simpletree
treeBuilderCache[treeType] = simpletree.TreeBuilder
elif treeType == "beautifulsoup":
- import soup
+ from . import soup
treeBuilderCache[treeType] = soup.TreeBuilder
elif treeType == "lxml":
- import etree_lxml
+ from . import etree_lxml
treeBuilderCache[treeType] = etree_lxml.TreeBuilder
elif treeType == "etree":
if implementation is None:
View
15 src/html5lib/treebuilders/etree_lxml.py
@@ -1,9 +1,8 @@
-import _base
-import new
+from . import _base
import warnings
-from html5lib.constants import DataLossWarning
-import etree as etree_builders
-from html5lib import ihatexml
+from ..constants import DataLossWarning
+from . import etree as etree_builders
+from .. import ihatexml
try:
import lxml.etree as etree
@@ -158,7 +157,7 @@ class Attributes(dict):
def __init__(self, element, value={}):
self._element = element
dict.__init__(self, value)
- for k, v in self.iteritems():
+ for k, v in self.items():
self._element._element.attrib[filter.coerceAttribute(k)] = v
def __setitem__(self, key, value):
@@ -263,7 +262,7 @@ def insertRoot(self, token):
"""Create the document root"""
#Because of the way libxml2 works, it doesn't seem to be possible to
#alter information like the doctype after the tree has been parsed.
- #Therefore we need to use the built-in parser to create our iniial
+ #Therefore we need to use the built-in parser to create our initial
#tree, after which we can add elements like normal
docStr = ""
if self.doctype and self.doctype.name:
@@ -278,7 +277,7 @@ def insertRoot(self, token):
try:
root = etree.fromstring(docStr)
except etree.XMLSyntaxError:
- print docStr
+ print(docStr)
raise
#Append the initial comments:

0 comments on commit dbcb5fc

Please sign in to comment.