From 9b6056fc9a7b723e198c8db8bc6ce498a91aff97 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 24 Jun 2015 17:11:48 -0400 Subject: Made double sure that we don't use the 'strict' constructor argument when it's deprecated. [bug=1341055] --- bs4/builder/_htmlparser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bs4/builder/_htmlparser.py') diff --git a/bs4/builder/_htmlparser.py b/bs4/builder/_htmlparser.py index 7f3ae73..afd94dd 100644 --- a/bs4/builder/_htmlparser.py +++ b/bs4/builder/_htmlparser.py @@ -20,8 +20,10 @@ import warnings # strict=True works well on Python 3.2.2. major, minor, release = sys.version_info[:3] CONSTRUCTOR_TAKES_STRICT = major == 3 and minor == 2 and release >= 3 +CONSTRUCTOR_STRICT_IS_DEPRECATED = major == 3 and minor == 3 CONSTRUCTOR_TAKES_CONVERT_CHARREFS = major == 3 and minor >= 4 + from bs4.element import ( CData, Comment, @@ -123,7 +125,7 @@ class HTMLParserTreeBuilder(HTMLTreeBuilder): features = [NAME, HTML, STRICT] def __init__(self, *args, **kwargs): - if CONSTRUCTOR_TAKES_STRICT: + if CONSTRUCTOR_TAKES_STRICT and not CONSTRUCTOR_STRICT_IS_DEPRECATED: kwargs['strict'] = False if CONSTRUCTOR_TAKES_CONVERT_CHARREFS: kwargs['convert_charrefs'] = False -- cgit v1.2.3 From 0c721728089eae05a0cab8ca04307dc859587470 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 24 Jun 2015 17:22:13 -0400 Subject: Fixed an import error in Python 3.5 caused by the removal of the --- bs4/builder/_htmlparser.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bs4/builder/_htmlparser.py') diff --git a/bs4/builder/_htmlparser.py b/bs4/builder/_htmlparser.py index afd94dd..b2cd467 100644 --- a/bs4/builder/_htmlparser.py +++ b/bs4/builder/_htmlparser.py @@ -4,10 +4,16 @@ __all__ = [ 'HTMLParserTreeBuilder', ] -from HTMLParser import ( - HTMLParser, - HTMLParseError, - ) +from HTMLParser import HTMLParser + +try: + from HTMLParser import HTMLParseError +except ImportError, e: + # HTMLParseError is removed in Python 3.5. Since it can never be + # thrown in 3.5, we can just define our own class as a placeholder. + class HTMLParseError(Exception): + pass + import sys import warnings -- cgit v1.2.3