diff options
author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-01-12 20:32:26 +0000 |
---|---|---|
committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-01-12 23:11:55 +0000 |
commit | 89f12c0596db201c7d052120d4337a36bc0aab17 (patch) | |
tree | bf8cde86be0933623ad4c4ac2fa43a5aa9ab0581 /django/utils/html_parser.py | |
parent | 0a7588dd3f5ec5beef0298389661e78fd63ad6a6 (diff) | |
download | django-89f12c0596db201c7d052120d4337a36bc0aab17.tar.gz |
Add further workarounds for HTMLParser with Python 3.4.
Python 3.5 will change the default value of convert_charrefs, so 3.4
gives warnings if it's not present. This is slightly technical as 2.7
doesn't have the kwarg. Thankfully, we already have a bunch of
workarounds for different versions.
Diffstat (limited to 'django/utils/html_parser.py')
-rw-r--r-- | django/utils/html_parser.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py index fe71172cfd..6b99cd707f 100644 --- a/django/utils/html_parser.py +++ b/django/utils/html_parser.py @@ -12,7 +12,18 @@ use_workaround = ( HTMLParseError = _html_parser.HTMLParseError if not use_workaround: - HTMLParser = _html_parser.HTMLParser + if current_version >= (3, 4): + class HTMLParser(_html_parser.HTMLParser): + """Explicitly set convert_charrefs to be False. + + 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): + _html_parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs) + else: + HTMLParser = _html_parser.HTMLParser else: tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') |