summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2015-06-24 17:22:13 -0400
committerLeonard Richardson <leonardr@segfault.org>2015-06-24 17:22:13 -0400
commit0c721728089eae05a0cab8ca04307dc859587470 (patch)
tree28f3852c08889ba50b32f4c6adaec8ff201f8b01
parent9b6056fc9a7b723e198c8db8bc6ce498a91aff97 (diff)
Fixed an import error in Python 3.5 caused by the removal of the
-rw-r--r--NEWS.txt3
-rw-r--r--bs4/builder/_htmlparser.py14
2 files changed, 13 insertions, 4 deletions
diff --git a/NEWS.txt b/NEWS.txt
index d49d451..e3c5938 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -44,6 +44,9 @@
'class', the html5lib tree builder will now turn its value into a
list, as it would with any other tag. [bug=1296481]
+* Fixed an import error in Python 3.5 caused by the removal of the
+ HTMLParseError class. [bug=1420063]
+
* Improved docstring for encode_contents() and
decode_contents(). [bug=1441543]
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