2015-06-15 21:43:35 +08:00
|
|
|
from django.utils import six
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.utils.six.moves import html_parser as _html_parser
|
|
|
|
|
2014-11-05 09:56:00 +08:00
|
|
|
try:
|
|
|
|
HTMLParseError = _html_parser.HTMLParseError
|
|
|
|
except AttributeError:
|
|
|
|
# create a dummy class for Python 3.5+ where it's been removed
|
|
|
|
class HTMLParseError(Exception):
|
|
|
|
pass
|
2012-07-20 22:16:57 +08:00
|
|
|
|
2016-03-26 18:35:50 +08:00
|
|
|
if six.PY3:
|
2012-08-17 03:03:11 +08:00
|
|
|
class HTMLParser(_html_parser.HTMLParser):
|
2016-03-26 18:35:50 +08:00
|
|
|
"""Explicitly set convert_charrefs to be False.
|
2012-02-01 04:36:11 +08:00
|
|
|
|
2016-03-26 18:35:50 +08:00
|
|
|
This silences a deprecation warning on Python 3.4, but we can't do
|
|
|
|
it at call time because Python 2.7 does not have the keyword
|
|
|
|
argument.
|
|
|
|
"""
|
|
|
|
def __init__(self, convert_charrefs=False, **kwargs):
|
|
|
|
_html_parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs)
|
|
|
|
else:
|
|
|
|
HTMLParser = _html_parser.HTMLParser
|