From bda96122730e7cebc8cfa7d64d3ffe9edbde9114 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Thu, 14 May 2020 20:15:28 +0100 Subject: [PATCH] Make html.escape Python 3 only --- linkcheck/checker/__init__.py | 6 +++--- linkcheck/lc_cgi.py | 4 ++-- linkcheck/logger/html.py | 24 ++++++++++++------------ scripts/analyze_memdump.py | 4 ++-- tests/checker/httpserver.py | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/linkcheck/checker/__init__.py b/linkcheck/checker/__init__.py index 056bc95d..60c2fe93 100644 --- a/linkcheck/checker/__init__.py +++ b/linkcheck/checker/__init__.py @@ -18,7 +18,7 @@ Main functions for link checking. """ import os -from html import escape as html_escape +import html import urllib.parse from .. import strformat, url as urlutil, log, LOG_CHECK @@ -163,9 +163,9 @@ def get_index_html (urls): """ lines = ["", ""] for entry in urls: - name = html_escape(entry) + name = html.escape(entry) try: - url = html_escape(urllib.parse.quote(entry)) + url = html.escape(urllib.parse.quote(entry)) except KeyError: # Some unicode entries raise KeyError. url = name diff --git a/linkcheck/lc_cgi.py b/linkcheck/lc_cgi.py index 29b71c91..5b5a7f6c 100644 --- a/linkcheck/lc_cgi.py +++ b/linkcheck/lc_cgi.py @@ -17,7 +17,7 @@ Functions used by the WSGI script. """ -from html import escape as html_escape +import html import os import threading import locale @@ -261,4 +261,4 @@ contains only these characters: A-Za-z0-9./_~-

Errors are logged. -""") % html_escape(why) +""") % html.escape(why) diff --git a/linkcheck/logger/html.py b/linkcheck/logger/html.py index 95bc5d1c..259cf311 100644 --- a/linkcheck/logger/html.py +++ b/linkcheck/logger/html.py @@ -17,7 +17,7 @@ A HTML logger. """ -from html import escape as html_escape +import html import os import time @@ -174,12 +174,12 @@ class HtmlLogger (_Logger): self.writeln("") self.writeln('%s' % self.part("url")) self.write('') - self.write("`%s'" % html_escape(url_data.base_url)) + self.write("`%s'" % html.escape(url_data.base_url)) self.writeln("") def write_name (self, url_data): """Write url_data.name.""" - args = (self.part("name"), html_escape(url_data.name)) + args = (self.part("name"), html.escape(url_data.name)) self.writeln("%s`%s'" % args) def write_parent (self, url_data): @@ -187,7 +187,7 @@ class HtmlLogger (_Logger): self.write(""+self.part("parenturl")+ ''+ - html_escape(url_data.parent_url)+"") + html.escape(url_data.parent_url)+"") if url_data.line is not None: self.write(_(", line %d") % url_data.line) if url_data.column is not None: @@ -206,13 +206,13 @@ class HtmlLogger (_Logger): def write_base (self, url_data): """Write url_data.base_ref.""" self.writeln(""+self.part("base")+""+ - html_escape(url_data.base_ref)+"") + html.escape(url_data.base_ref)+"") def write_real (self, url_data): """Write url_data.url.""" self.writeln(""+self.part("realurl")+""+ ''+html_escape(url_data.url)+"") + '">'+html.escape(url_data.url)+"") def write_dltime (self, url_data): """Write url_data.dltime.""" @@ -234,20 +234,20 @@ class HtmlLogger (_Logger): def write_info (self, url_data): """Write url_data.info.""" sep = "
"+os.linesep - text = sep.join(html_escape(x) for x in url_data.info) + text = sep.join(html.escape(x) for x in url_data.info) self.writeln('' + self.part("info")+ ""+text+"") def write_modified(self, url_data): """Write url_data.modified.""" - text = html_escape(self.format_modified(url_data.modified)) + text = html.escape(self.format_modified(url_data.modified)) self.writeln('' + self.part("modified") + ""+text+"") def write_warning (self, url_data): """Write url_data.warnings.""" sep = "
"+os.linesep - text = sep.join(html_escape(x[1]) for x in url_data.warnings) + text = sep.join(html.escape(x[1]) for x in url_data.warnings) self.writeln('' + self.part("warning") + '' + text + "") @@ -258,14 +258,14 @@ class HtmlLogger (_Logger): self.write('') self.write(self.part("result")) self.write('') - self.write(html_escape(_("Valid"))) + self.write(html.escape(_("Valid"))) else: self.write('') self.write(self.part("result")) self.write('') - self.write(html_escape(_("Error"))) + self.write(html.escape(_("Error"))) if url_data.result: - self.write(": "+html_escape(url_data.result)) + self.write(": "+html.escape(url_data.result)) self.writeln("") def write_stats (self): diff --git a/scripts/analyze_memdump.py b/scripts/analyze_memdump.py index 06ac62f7..64aff639 100755 --- a/scripts/analyze_memdump.py +++ b/scripts/analyze_memdump.py @@ -20,7 +20,7 @@ Analyze a memory dump by the meliae module. import sys import os import codecs -from html import escape as html_escape +import html from linkcheck import strformat def main (filename): @@ -107,7 +107,7 @@ def write_html_obj(fp, obj, objs): if obj.value is None: value = "None" else: - value = html_escape(str(obj.value)) + value = html.escape(str(obj.value)) attrs = dict( address=obj.address, size=strformat.strsize(obj.size), diff --git a/tests/checker/httpserver.py b/tests/checker/httpserver.py index 19839164..b90a9836 100644 --- a/tests/checker/httpserver.py +++ b/tests/checker/httpserver.py @@ -17,7 +17,7 @@ Define http test support classes for LinkChecker tests. """ -from html import escape as html_escape +import html from http.server import CGIHTTPRequestHandler, SimpleHTTPRequestHandler, HTTPServer from http.client import HTTPConnection, HTTPSConnection import os.path @@ -133,7 +133,7 @@ class NoQueryHttpRequestHandler (StoppableHttpRequestHandler): displayname = linkname = name list_item = ( '
  • %s\n' - % (urllib.parse.quote(linkname), html_escape(displayname)) + % (urllib.parse.quote(linkname), html.escape(displayname)) ) f.write(list_item.encode()) f.write(b"\n
    \n\n\n")