[Python-checkins] peps: cgi.escape is deprecated, use html.escape instead.

serhiy.storchaka python-checkins at python.org
Tue May 3 03:51:43 EDT 2016


https://hg.python.org/peps/rev/396f1d06e92a
changeset:   6300:396f1d06e92a
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue May 03 10:51:13 2016 +0300
summary:
  cgi.escape is deprecated, use html.escape instead.

files:
  pep2html.py |  20 ++++++++++++--------
  1 files changed, 12 insertions(+), 8 deletions(-)


diff --git a/pep2html.py b/pep2html.py
--- a/pep2html.py
+++ b/pep2html.py
@@ -46,6 +46,10 @@
 import random
 import time
 from io import open
+try:
+    from html import escape
+except ImportError:
+    from cgi import escape
 
 REQUIRES = {'python': '2.6',
             'docutils': '0.2.7'}
@@ -117,8 +121,8 @@
         rfcnum = int(match.group('rfcnum'))
         link = RFCURL % rfcnum
     if link:
-        return '<a href="%s">%s</a>' % (cgi.escape(link), cgi.escape(text))
-    return cgi.escape(match.group(0)) # really slow, but it works...
+        return '<a href="%s">%s</a>' % (escape(link), escape(text))
+    return escape(match.group(0)) # really slow, but it works...
 
 
 

@@ -182,7 +186,7 @@
     if pep:
         title = "PEP " + pep + " -- " + title
     if title:
-        print('  <title>%s</title>' % cgi.escape(title), file=outfile)
+        print('  <title>%s</title>' % escape(title), file=outfile)
     r = random.choice(list(range(64)))
     print((
         '  <link rel="STYLESHEET" href="style.css" type="text/css" />\n'
@@ -241,20 +245,20 @@
             else:
                 try:
                     url = PEPCVSURL % int(pep)
-                    v = '<a href="%s">%s</a> ' % (url, cgi.escape(date))
+                    v = '<a href="%s">%s</a> ' % (url, escape(date))
                 except ValueError as error:
                     v = date
         elif k.lower() in ('content-type',):
             url = PEPURL % 9
             pep_type = v or 'text/plain'
-            v = '<a href="%s">%s</a> ' % (url, cgi.escape(pep_type))
+            v = '<a href="%s">%s</a> ' % (url, escape(pep_type))
         elif k.lower() == 'version':
             if v.startswith('$' 'Revision: ') and v.endswith(' $'):
-                v = cgi.escape(v[11:-2])
+                v = escape(v[11:-2])
         else:
-            v = cgi.escape(v)
+            v = escape(v)
         print('  <tr><th>%s: </th><td>%s</td></tr>' \
-              % (cgi.escape(k), v), file=outfile)
+              % (escape(k), v), file=outfile)
     print('</table>', file=outfile)
     print('</div>', file=outfile)
     print('<hr />', file=outfile)

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list