Fix the DeprecationWarning for unescape (#23936)

This PR solves the DeprecationWarning mentioned in:
https://build.testeng.edx.org/job/edx-platform-python-pipeline-master/warning_5freport_5fall_2ehtml/

HTMLParser was renamed in html.parser in Python3:
https://docs.python.org/2/library/htmlparser.html#module-HTMLParser

* html_parser.HTMLParser().unescape from six.moves has been deprecated

* instead use html.unescape from Python3

Documentation for unescape in Python3:
https://docs.python.org/3/library/html.html#html.unescape

- html_parser from six.moves has been deprecated

- instead use html.parser from Python3

- Order imports using isort

- Delete unused import crum
This commit is contained in:
Leonardo Martinez
2020-06-19 08:27:45 -05:00
committed by GitHub
parent 137fd0a96e
commit b4fee68283
4 changed files with 27 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ This file contains utility functions which will responsible for sending emails.
import logging
import os
import uuid
import html
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
@@ -106,8 +107,7 @@ def send_credit_notifications(username, course_key):
cur_text = cur_file.read()
# use html parser to unescape html characters which are changed
# by the 'pynliner' while adding inline css to html content
html_parser = six.moves.html_parser.HTMLParser()
email_body_content = html_parser.unescape(with_inline_css(cur_text))
email_body_content = html.unescape(with_inline_css(cur_text))
# cache the email body content before rendering it since the
# email context will change for each user e.g., 'full_name'
cache.set('credit.email.css-email-body', email_body_content, settings.CREDIT_NOTIFICATION_CACHE_TIMEOUT)