From cfff2af02be40106d4759cc6f8bfa476ce82421c Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 17 Feb 2017 19:45:34 -0500 Subject: Fixed #27857 -- Dropped support for Python 3.4. --- django/utils/html.py | 18 +++++------------- django/utils/html_parser.py | 17 ----------------- 2 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 django/utils/html_parser.py (limited to 'django/utils') diff --git a/django/utils/html.py b/django/utils/html.py index 9f4f58c7a1..e365cd41f6 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -1,6 +1,7 @@ """HTML utilities suitable for global use.""" import re +from html.parser import HTMLParser from urllib.parse import ( parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit, ) @@ -11,8 +12,6 @@ from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS from django.utils.safestring import SafeData, SafeText, mark_safe from django.utils.text import normalize_newlines -from .html_parser import HTMLParseError, HTMLParser - # Configuration for urlize() function. TRAILING_PUNCTUATION_RE = re.compile( '^' # Beginning of word @@ -132,7 +131,7 @@ def linebreaks(value, autoescape=False): class MLStripper(HTMLParser): def __init__(self): - HTMLParser.__init__(self) + HTMLParser.__init__(self, convert_charrefs=False) self.reset() self.fed = [] @@ -154,16 +153,9 @@ def _strip_once(value): Internal tag stripping utility used by strip_tags. """ s = MLStripper() - try: - s.feed(value) - except HTMLParseError: - return value - try: - s.close() - except HTMLParseError: - return s.get_data() + s.rawdata - else: - return s.get_data() + s.feed(value) + s.close() + return s.get_data() @keep_lazy_text diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py deleted file mode 100644 index 6b46ddc368..0000000000 --- a/django/utils/html_parser.py +++ /dev/null @@ -1,17 +0,0 @@ -import html.parser - -try: - HTMLParseError = html.parser.HTMLParseError -except AttributeError: - # create a dummy class for Python 3.5+ where it's been removed - class HTMLParseError(Exception): - pass - - -class HTMLParser(html.parser.HTMLParser): - """Explicitly set convert_charrefs to be False. - - This silences a deprecation warning on Python 3.4. - """ - def __init__(self, convert_charrefs=False, **kwargs): - html.parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs) -- cgit v1.3