webconfig: Use html.escape if available

Just try to import it, on error import the old thing.

Tested with python 3.7.1 and 2.7.15.

Fixes #5125.

[ci skip]
This commit is contained in:
Fabian Homborg 2018-11-30 19:44:20 +01:00
parent 35db0fb5df
commit 91a664b9fa

View file

@ -4,6 +4,10 @@ from __future__ import unicode_literals
from __future__ import print_function from __future__ import print_function
import binascii import binascii
import cgi import cgi
try:
from html import escape as escape_html
except ImportError:
from cgi import escape as escape_html
from distutils.version import LooseVersion from distutils.version import LooseVersion
import glob import glob
import multiprocessing.pool import multiprocessing.pool
@ -322,7 +326,7 @@ def ansi_to_html(val):
if i % 2 == 0: if i % 2 == 0:
# It's text, possibly empty # It's text, possibly empty
# Clean up other ANSI junk # Clean up other ANSI junk
result.append(cgi.escape(strip_ansi(component))) result.append(escape_html(strip_ansi(component)))
else: else:
# It's an escape sequence. Close the previous escape. # It's an escape sequence. Close the previous escape.
span_open = append_html_for_ansi_escape(component, result, span_open = append_html_for_ansi_escape(component, result,