python3: use our bytes-only version of cgi.escape everywhere
authorAugie Fackler <augie@google.com>
Thu, 05 Oct 2017 14:16:20 -0400
changeset 34695 e178fcaa3933
parent 34694 2976cf87a60a
child 34696 15b561fffde5
python3: use our bytes-only version of cgi.escape everywhere As suggested by Yuya in D965. Differential Revision: https://phab.mercurial-scm.org/D1067
mercurial/hgweb/webcommands.py
mercurial/minirst.py
mercurial/templatefilters.py
--- a/mercurial/hgweb/webcommands.py	Sat Oct 14 02:57:26 2017 -0400
+++ b/mercurial/hgweb/webcommands.py	Thu Oct 05 14:16:20 2017 -0400
@@ -7,7 +7,6 @@
 
 from __future__ import absolute_import
 
-import cgi
 import copy
 import mimetypes
 import os
@@ -38,6 +37,7 @@
     smartset,
     templatefilters,
     templater,
+    url,
     util,
 )
 
@@ -1250,9 +1250,9 @@
             node = str(ctx)
             age = encodestr(templatefilters.age(ctx.date()))
             desc = templatefilters.firstline(encodestr(ctx.description()))
-            desc = cgi.escape(templatefilters.nonempty(desc))
-            user = cgi.escape(templatefilters.person(encodestr(ctx.user())))
-            branch = cgi.escape(encodestr(ctx.branch()))
+            desc = url.escape(templatefilters.nonempty(desc))
+            user = url.escape(templatefilters.person(encodestr(ctx.user())))
+            branch = url.escape(encodestr(ctx.branch()))
             try:
                 branchnode = web.repo.branchtip(branch)
             except error.RepoLookupError:
@@ -1261,8 +1261,8 @@
 
             if usetuples:
                 data.append((node, vtx, edges, desc, user, age, branch,
-                             [cgi.escape(encodestr(x)) for x in ctx.tags()],
-                             [cgi.escape(encodestr(x))
+                             [url.escape(encodestr(x)) for x in ctx.tags()],
+                             [url.escape(encodestr(x))
                               for x in ctx.bookmarks()]))
             else:
                 edgedata = [{'col': edge[0], 'nextcol': edge[1],
--- a/mercurial/minirst.py	Sat Oct 14 02:57:26 2017 -0400
+++ b/mercurial/minirst.py	Thu Oct 05 14:16:20 2017 -0400
@@ -20,13 +20,13 @@
 
 from __future__ import absolute_import
 
-import cgi
 import re
 
 from .i18n import _
 from . import (
     encoding,
     pycompat,
+    url,
     util,
 )
 
@@ -552,7 +552,7 @@
     listnest = []
 
     def escape(s):
-        return cgi.escape(s, True)
+        return url.escape(s, True)
 
     def openlist(start, level):
         if not listnest or listnest[-1][0] != start:
--- a/mercurial/templatefilters.py	Sat Oct 14 02:57:26 2017 -0400
+++ b/mercurial/templatefilters.py	Thu Oct 05 14:16:20 2017 -0400
@@ -7,7 +7,6 @@
 
 from __future__ import absolute_import
 
-import cgi
 import os
 import re
 import time
@@ -19,6 +18,7 @@
     pycompat,
     registrar,
     templatekw,
+    url,
     util,
 )
 
@@ -128,7 +128,7 @@
     """Any text. Replaces the special XML/XHTML characters "&", "<"
     and ">" with XML entities, and filters out NUL characters.
     """
-    return cgi.escape(text.replace('\0', ''), True)
+    return url.escape(text.replace('\0', ''), True)
 
 para_re = None
 space_re = None