9ab882f
From ae41cdd0d2af39c3a6a1c5a256f865de71a93ce4 Mon Sep 17 00:00:00 2001
b62afc4
From: Neal Gompa <ngompa13@gmail.com>
b62afc4
Date: Mon, 18 Nov 2019 01:01:27 -0500
b62afc4
Subject: [PATCH] Swap all usage of cgi.escape() with html.escape()
b62afc4
b62afc4
In Python 3.8, cgi.escape() has been completely removed after
b62afc4
being deprecated since Python 3.2. The suggested replacement
b62afc4
is to use html.escape().
b62afc4
---
b62afc4
 osc/commandline.py | 28 ++++++++++++++--------------
b62afc4
 osc/core.py        | 14 +++++++-------
b62afc4
 2 files changed, 21 insertions(+), 21 deletions(-)
b62afc4
b62afc4
diff --git a/osc/commandline.py b/osc/commandline.py
9ab882f
index 2b94b14..c3712c8 100644
b62afc4
--- a/osc/commandline.py
b62afc4
+++ b/osc/commandline.py
b62afc4
@@ -1241,7 +1241,7 @@ class Osc(cmdln.Cmdln):
b62afc4
         if len(args) < 2 and is_project_dir(os.getcwd()):
b62afc4
             if opts.diff:
b62afc4
                 raise oscerr.WrongOptions('\'--diff\' is not supported in a project working copy')
b62afc4
-            import cgi
b62afc4
+            import html
b62afc4
             project = store_read_project(os.curdir)
b62afc4
 
b62afc4
             sr_ids = []
b62afc4
@@ -1295,7 +1295,7 @@ class Osc(cmdln.Cmdln):
b62afc4
                         (project, target_prj_block, options_block)
b62afc4
                 actionxml += s
b62afc4
                 xml = """<request> %s <state name="new"/> <description>%s</description> </request> """ % \
b62afc4
-                        (actionxml, cgi.escape(opts.message or ""))
9ab882f
+                        (actionxml, html.escape(opts.message or "", False))
b62afc4
                 u = makeurl(apiurl, ['request'], query='cmd=create&addrevision=1')
b62afc4
                 f = http_POST(u, data=xml)
b62afc4
 
b62afc4
@@ -1864,9 +1864,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
         if not opts.message:
b62afc4
             opts.message = edit_message()
b62afc4
 
b62afc4
-        import cgi
b62afc4
+        import html
b62afc4
         xml = """<request> %s <state name="new"/> <description>%s</description> </request> """ % \
b62afc4
-              (actionsxml, cgi.escape(opts.message or ""))
9ab882f
+              (actionsxml, html.escape(opts.message or "", False))
b62afc4
         u = makeurl(apiurl, ['request'], query='cmd=create')
b62afc4
         f = http_POST(u, data=xml)
b62afc4
 
b62afc4
@@ -1903,7 +1903,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
 
b62afc4
         ${cmd_option_list}
b62afc4
         """
b62afc4
-        import cgi
b62afc4
+        import html
b62afc4
         args = slash_split(args)
b62afc4
         apiurl = self.get_api_url()
b62afc4
 
b62afc4
@@ -1958,7 +1958,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
         else:
b62afc4
             r.add_action('add_role', tgt_project=project, tgt_package=package,
b62afc4
               person_name=user, person_role=role)
b62afc4
-        r.description = cgi.escape(opts.message or '')
b62afc4
+        r.description = html.escape(opts.message or '', False)
b62afc4
         r.create(apiurl)
b62afc4
         print(r.reqid)
b62afc4
 
b62afc4
@@ -1983,7 +1983,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
             osc deletereq [-m TEXT] PROJECT [--all|--repository REPOSITORY]
b62afc4
         ${cmd_option_list}
b62afc4
         """
b62afc4
-        import cgi
b62afc4
+        import html
b62afc4
 
b62afc4
         args = slash_split(args)
b62afc4
 
b62afc4
@@ -2025,7 +2025,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
 
b62afc4
         r = Request()
b62afc4
         r.add_action('delete', tgt_project=project, tgt_package=package, tgt_repository=repository)
b62afc4
-        r.description = cgi.escape(opts.message)
b62afc4
+        r.description = html.escape(opts.message, False)
b62afc4
         if opts.accept_in_hours:
b62afc4
           r.accept_at_in_hours(int(opts.accept_in_hours))
b62afc4
         r.create(self.get_api_url())
b62afc4
@@ -2046,7 +2046,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
 
b62afc4
         osc changedevelrequest PROJECT PACKAGE DEVEL_PROJECT [DEVEL_PACKAGE]
b62afc4
         """
b62afc4
-        import cgi
b62afc4
+        import html
b62afc4
 
b62afc4
         if len(args) == 0 and is_package_dir('.') and find_default_project():
b62afc4
             wd = os.curdir
b62afc4
@@ -2075,7 +2075,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
         r = Request()
b62afc4
         r.add_action('change_devel', src_project=devel_project, src_package=devel_package,
b62afc4
             tgt_project=project, tgt_package=package)
b62afc4
-        r.description = cgi.escape(opts.message)
b62afc4
+        r.description = html.escape(opts.message, False)
b62afc4
         r.create(self.get_api_url())
b62afc4
         print(r.reqid)
b62afc4
 
b62afc4
@@ -2601,7 +2601,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
 
b62afc4
                 # check for devel instances after accepted requests
b62afc4
                 if cmd in ['accept']:
b62afc4
-                    import cgi
b62afc4
+                    import html
b62afc4
                     sr_actions = rq.get_actions('submit')
b62afc4
                     for action in sr_actions:
b62afc4
                         u = makeurl(apiurl, ['/search/package'], {
b62afc4
@@ -2641,7 +2641,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
                                                                                 project, package)
b62afc4
                                     msg = "%s (forwarded request %s from %s)" % (rq.description, reqid, rq.creator)
b62afc4
                                     rid = create_submit_request(apiurl, action.tgt_project, action.tgt_package,
b62afc4
-                                                                project, package, cgi.escape(msg))
b62afc4
+                                                                project, package, html.escape(msg, False))
b62afc4
                                     print(msg)
b62afc4
                                     print("New request #", rid)
b62afc4
                                     for req in reqs:
b62afc4
@@ -8270,9 +8270,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
b62afc4
                 else:
b62afc4
                     message = edit_message()
b62afc4
 
b62afc4
-                import cgi
b62afc4
+                import html
b62afc4
                 xml = """<request> %s <state name="new"/> <description>%s</description> </request> """ % \
b62afc4
-                      (requestactionsxml, cgi.escape(message or ""))
b62afc4
+                      (requestactionsxml, html.escape(message or "", False))
b62afc4
                 u = makeurl(apiurl, ['request'], query='cmd=create')
b62afc4
                 f = http_POST(u, data=xml)
b62afc4
 
b62afc4
diff --git a/osc/core.py b/osc/core.py
9ab882f
index b1289e4..4dba361 100644
b62afc4
--- a/osc/core.py
b62afc4
+++ b/osc/core.py
b62afc4
@@ -4172,18 +4172,18 @@ def clone_request(apiurl, reqid, msg=None):
b62afc4
 
b62afc4
 # create a maintenance release request
b62afc4
 def create_release_request(apiurl, src_project, message=''):
b62afc4
-    import cgi
b62afc4
+    import html
b62afc4
     r = Request()
b62afc4
     # api will complete the request
b62afc4
     r.add_action('maintenance_release', src_project=src_project)
b62afc4
     # XXX: clarify why we need the unicode(...) stuff
b62afc4
-    r.description = cgi.escape(unicode(message, 'utf8'))
b62afc4
+    r.description = html.escape(unicode(message, 'utf8'), False)
b62afc4
     r.create(apiurl)
b62afc4
     return r
b62afc4
 
b62afc4
 # create a maintenance incident per request
b62afc4
 def create_maintenance_request(apiurl, src_project, src_packages, tgt_project, tgt_releaseproject, opt_sourceupdate, message='', enforce_branching=False):
b62afc4
-    import cgi
b62afc4
+    import html
b62afc4
     r = Request()
b62afc4
     if src_packages:
b62afc4
         for p in src_packages:
b62afc4
@@ -4191,7 +4191,7 @@ def create_maintenance_request(apiurl, src_project, src_packages, tgt_project, t
b62afc4
     else:
b62afc4
         r.add_action('maintenance_incident', src_project=src_project, tgt_project=tgt_project, tgt_releaseproject=tgt_releaseproject, opt_sourceupdate = opt_sourceupdate)
b62afc4
     # XXX: clarify why we need the unicode(...) stuff
b62afc4
-    r.description = cgi.escape(unicode(message, 'utf8'))
b62afc4
+    r.description = html.escape(unicode(message, 'utf8'), False)
b62afc4
     r.create(apiurl, addrevision=True, enforce_branching=enforce_branching)
b62afc4
     return r
b62afc4
 
b62afc4
@@ -4200,7 +4200,7 @@ def create_submit_request(apiurl,
b62afc4
                          dst_project=None, dst_package=None,
b62afc4
                          message="", orev=None, src_update=None, dst_updatelink=None):
b62afc4
 
b62afc4
-    import cgi
b62afc4
+    import html
b62afc4
     options_block = ""
b62afc4
     package = ""
b62afc4
     if src_package:
b62afc4
@@ -4236,9 +4236,9 @@ def create_submit_request(apiurl,
b62afc4
        orev or show_upstream_rev(apiurl, src_project, src_package),
b62afc4
        targetxml,
b62afc4
        options_block,
b62afc4
-       cgi.escape(message))
b62afc4
+       html.escape(message, False))
b62afc4
 
b62afc4
-    # Don't do cgi.escape(unicode(message, "utf8"))) above.
b62afc4
+    # Don't do html.escape(unicode(message, "utf8")), False) above.
b62afc4
     # Promoting the string to utf8, causes the post to explode with:
b62afc4
     #   uncaught exception: Fatal error: Start tag expected, '<' not found at :1.
b62afc4
     # I guess, my original workaround was not that bad.
b62afc4
-- 
b62afc4
2.21.0
b62afc4