Commit 5c79dd58 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #18239 -- Subclassed HTMLParser only for selected Python versions

Only Python versions affected by http://bugs.python.org/issue670664
should patch HTMLParser.
Thanks Raphaël Hertzog for the initial patch (for 1.4).
parent 37a894b4
Loading
Loading
Loading
Loading
+100 −88
Original line number Diff line number Diff line
from django.utils.six.moves import html_parser as _html_parser
import re
import sys

tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
current_version = sys.version_info

use_workaround = (
    (current_version < (2, 6, 8)) or
    (current_version >= (2, 7) and current_version < (2, 7, 3)) or
    (current_version >= (3, 0) and current_version < (3, 2, 3))
)

HTMLParseError = _html_parser.HTMLParseError

if not use_workaround:
    HTMLParser = _html_parser.HTMLParser
else:
    tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')

    class HTMLParser(_html_parser.HTMLParser):
        """
        Patched version of stdlib's HTMLParser with patch from: