From 91a664b9fa014a887f6fd84b8fa8b8b8fe9ff4e0 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 30 Nov 2018 19:44:20 +0100 Subject: [PATCH] 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] --- share/tools/web_config/webconfig.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index 181948972..47555dec4 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -4,6 +4,10 @@ from __future__ import unicode_literals from __future__ import print_function import binascii import cgi +try: + from html import escape as escape_html +except ImportError: + from cgi import escape as escape_html from distutils.version import LooseVersion import glob import multiprocessing.pool @@ -322,7 +326,7 @@ def ansi_to_html(val): if i % 2 == 0: # It's text, possibly empty # Clean up other ANSI junk - result.append(cgi.escape(strip_ansi(component))) + result.append(escape_html(strip_ansi(component))) else: # It's an escape sequence. Close the previous escape. span_open = append_html_for_ansi_escape(component, result,