fix: Use html.unescape for Python 3.9 compatibility.

This commit is contained in:
Karthikeyan Singaravelan 2020-11-26 13:30:07 +00:00
parent ce05cc15ed
commit 3a146580a8
2 changed files with 4 additions and 7 deletions

View file

@ -10,6 +10,7 @@ import json
import os
from bs4 import BeautifulSoup
from frappe.utils import cint, strip_html_tags
from frappe.utils.html_utils import unescape_html
from frappe.model.base_document import get_controller
from six import text_type
@ -345,11 +346,8 @@ def get_formatted_value(value, field):
:return:
"""
from six.moves.html_parser import HTMLParser
if getattr(field, 'fieldtype', None) in ["Text", "Text Editor"]:
h = HTMLParser()
value = h.unescape(frappe.safe_decode(value))
value = unescape_html(frappe.safe_decode(value))
value = (re.subn(r'<[\s]*(script|style).*?</\1>(?s)', '', text_type(value))[0])
value = ' '.join(value.split())
return field.label + " : " + strip_html_tags(text_type(value))

View file

@ -106,9 +106,8 @@ def get_icon_html(icon, small=False):
return "<i class='{icon}'></i>".format(icon=icon)
def unescape_html(value):
from six.moves.html_parser import HTMLParser
h = HTMLParser()
return h.unescape(value)
from html import unescape
return unescape(value)
# adapted from https://raw.githubusercontent.com/html5lib/html5lib-python/4aa79f113e7486c7ec5d15a6e1777bfe546d3259/html5lib/sanitizer.py
acceptable_elements = [