summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lublin <daniel@lublin.se>2016-12-05 18:42:05 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-26 13:19:41 +0100
commitbdf7a362ecdafd47f309b7a21feac4b94624f287 (patch)
tree31ce5ef897cd9e3c02dae5044dbf2bc933f08119
parent0f7fdaa8212a8b9f1f089d32e652400d6c4b4822 (diff)
downloadbitbake-contrib-bdf7a362ecdafd47f309b7a21feac4b94624f287.tar.gz
bitbake-contrib-bdf7a362ecdafd47f309b7a21feac4b94624f287.tar.bz2
bitbake-contrib-bdf7a362ecdafd47f309b7a21feac4b94624f287.zip
lib/bs4: Fix imports from html5lib >= 0.9999999/1.0b8
As of html5lib 0.9999999/1.0b8 (released on July 14, 2016), some modules have moved from _base to base. Handle this, while staying compatible with earlier versions. Signed-off-by: Daniel Lublin <daniel@lublin.se> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bs4/builder/_html5lib.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/bs4/builder/_html5lib.py b/lib/bs4/builder/_html5lib.py
index f0e5924ebb..2b7a70aa11 100644
--- a/lib/bs4/builder/_html5lib.py
+++ b/lib/bs4/builder/_html5lib.py
@@ -15,7 +15,14 @@ from bs4.element import (
whitespace_re,
)
import html5lib
+try:
+ # html5lib >= 0.99999999/1.0b9
+ from html5lib.treebuilders import base as treebuildersbase
+except ImportError:
+ # html5lib <= 0.9999999/1.0b8
+ from html5lib.treebuilders import _base as treebuildersbase
from html5lib.constants import namespaces
+
from bs4.element import (
Comment,
Doctype,
@@ -67,7 +74,7 @@ class HTML5TreeBuilder(HTMLTreeBuilder):
return '<html><head></head><body>%s</body></html>' % fragment
-class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
+class TreeBuilderForHtml5lib(treebuildersbase.TreeBuilder):
def __init__(self, soup, namespaceHTMLElements):
self.soup = soup
@@ -105,7 +112,7 @@ class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
return self.soup
def getFragment(self):
- return html5lib.treebuilders._base.TreeBuilder.getFragment(self).element
+ return treebuildersbase.TreeBuilder.getFragment(self).element
class AttrList(object):
def __init__(self, element):
@@ -137,9 +144,9 @@ class AttrList(object):
return name in list(self.attrs.keys())
-class Element(html5lib.treebuilders._base.Node):
+class Element(treebuildersbase.Node):
def __init__(self, element, soup, namespace):
- html5lib.treebuilders._base.Node.__init__(self, element.name)
+ treebuildersbase.Node.__init__(self, element.name)
self.element = element
self.soup = soup
self.namespace = namespace
@@ -324,7 +331,7 @@ class Element(html5lib.treebuilders._base.Node):
class TextNode(Element):
def __init__(self, element, soup):
- html5lib.treebuilders._base.Node.__init__(self, None)
+ treebuildersbase.Node.__init__(self, None)
self.element = element
self.soup = soup