From d241e5d5a9e9c01d88b3711a82a6114f846ffdb1 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 14 Jul 2018 15:35:24 -0400 Subject: Stopped HTMLParser from raising an exception in very rare cases of bad markup. [bug=1708831] --- bs4/builder/_lxml.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bs4/builder/_lxml.py') diff --git a/bs4/builder/_lxml.py b/bs4/builder/_lxml.py index d2ca287..3439271 100644 --- a/bs4/builder/_lxml.py +++ b/bs4/builder/_lxml.py @@ -5,9 +5,13 @@ __all__ = [ 'LXMLTreeBuilder', ] +try: + from collections.abc import Callable # Python 3.6 +except ImportError , e: + from collections import Callable + from io import BytesIO from StringIO import StringIO -import collections from lxml import etree from bs4.element import ( Comment, @@ -58,7 +62,7 @@ class LXMLTreeBuilderForXML(TreeBuilder): # Use the default parser. parser = self.default_parser(encoding) - if isinstance(parser, collections.Callable): + if isinstance(parser, Callable): # Instantiate the parser with default arguments parser = parser(target=self, strip_cdata=False, encoding=encoding) return parser -- cgit v1.2.3