Drop py2 support in gerrit and git related files

python3 is the only supported version of python in depot_tools.

Bug: 1475402
Change-Id: Ie4ee18d297081b3aa0206b8d7ce6461819bff0ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4809560
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/gerrit_client.py b/gerrit_client.py
index 9bda025..8ea4df4 100755
--- a/gerrit_client.py
+++ b/gerrit_client.py
@@ -9,20 +9,12 @@
   ./gerrit_client.py [command] [args]
 """
 
-from __future__ import print_function
-
 import json
 import logging
 import optparse
 import subcommand
 import sys
-
-if sys.version_info.major == 2:
-  import urlparse
-  from urllib import quote_plus
-else:
-  from urllib.parse import quote_plus
-  import urllib.parse as urlparse
+import urllib.parse
 
 import fix_encoding
 import gerrit_util
@@ -49,7 +41,7 @@
   assert opt.destination_branch, "--destination_branch not defined"
   for p in opt.params:
     assert '=' in p, '--param is key=value, not "%s"' % p
-  host = urlparse.urlparse(opt.host).netloc
+  host = urllib.parse.urlparse(opt.host).netloc
 
   limit = 100
   while True:
@@ -72,9 +64,9 @@
   parser.add_option('--branch', dest='branch', help='branch name')
 
   (opt, args) = parser.parse_args(args)
-  host = urlparse.urlparse(opt.host).netloc
-  project = quote_plus(opt.project)
-  branch = quote_plus(opt.branch)
+  host = urllib.parse.urlparse(opt.host).netloc
+  project = urllib.parse.quote_plus(opt.project)
+  branch = urllib.parse.quote_plus(opt.branch)
   result = gerrit_util.GetGerritBranch(host, project, branch)
   logging.info(result)
   write_result(result, opt)
@@ -94,7 +86,7 @@
   (opt, args) = parser.parse_args(args)
   assert opt.path, "--path not defined"
 
-  host = urlparse.urlparse(opt.host).netloc
+  host = urllib.parse.urlparse(opt.host).netloc
   kwargs = {}
   if opt.method:
     kwargs['reqtype'] = opt.method.upper()
@@ -122,9 +114,9 @@
   assert opt.branch, "--branch not defined"
   assert opt.commit, "--commit not defined"
 
-  project = quote_plus(opt.project)
-  host = urlparse.urlparse(opt.host).netloc
-  branch = quote_plus(opt.branch)
+  project = urllib.parse.quote_plus(opt.project)
+  host = urllib.parse.urlparse(opt.host).netloc
+  branch = urllib.parse.quote_plus(opt.branch)
   result = gerrit_util.GetGerritBranch(host, project, branch)
   if result:
     if not opt.allow_existent_branch:
@@ -161,9 +153,9 @@
   assert opt.tag, "--tag not defined"
   assert opt.commit, "--commit not defined"
 
-  project = quote_plus(opt.project)
-  host = urlparse.urlparse(opt.host).netloc
-  tag = quote_plus(opt.tag)
+  project = urllib.parse.quote_plus(opt.project)
+  host = urllib.parse.urlparse(opt.host).netloc
+  tag = urllib.parse.quote_plus(opt.tag)
   result = gerrit_util.CreateGerritTag(host, project, tag, opt.commit)
   logging.info(result)
   write_result(result, opt)
@@ -178,9 +170,9 @@
   assert opt.project, "--project not defined"
   assert opt.branch, "--branch not defined"
 
-  project = quote_plus(opt.project)
-  host = urlparse.urlparse(opt.host).netloc
-  branch = quote_plus(opt.branch)
+  project = urllib.parse.quote_plus(opt.project)
+  host = urllib.parse.urlparse(opt.host).netloc
+  branch = urllib.parse.quote_plus(opt.branch)
   result = gerrit_util.UpdateHead(host, project, branch)
   logging.info(result)
   write_result(result, opt)
@@ -193,8 +185,8 @@
   (opt, args) = parser.parse_args(args)
   assert opt.project, "--project not defined"
 
-  project = quote_plus(opt.project)
-  host = urlparse.urlparse(opt.host).netloc
+  project = urllib.parse.quote_plus(opt.project)
+  host = urllib.parse.urlparse(opt.host).netloc
   result = gerrit_util.GetHead(host, project)
   logging.info(result)
   write_result(result, opt)
@@ -224,7 +216,7 @@
     assert '=' in p, '--param is key=value, not "%s"' % p
 
   result = gerrit_util.QueryChanges(
-      urlparse.urlparse(opt.host).netloc,
+      urllib.parse.urlparse(opt.host).netloc,
       list(tuple(p.split('=', 1)) for p in opt.params),
       first_param=opt.query,
       start=opt.start,  # Default: None
@@ -244,7 +236,7 @@
   (opt, args) = parser.parse_args(args)
 
   result = gerrit_util.GetRelatedChanges(
-      urlparse.urlparse(opt.host).netloc,
+      urllib.parse.urlparse(opt.host).netloc,
       change=opt.change,
       revision=opt.revision,
   )
@@ -282,7 +274,7 @@
     params.append(('notify_details', {'CC': {'accounts': opt.cc_list}}))
 
   result = gerrit_util.CreateChange(
-      urlparse.urlparse(opt.host).netloc,
+      urllib.parse.urlparse(opt.host).netloc,
       opt.project,
       branch=opt.branch,
       subject=opt.subject,
@@ -304,7 +296,7 @@
   with open(opt.file) as f:
     data = f.read()
   result = gerrit_util.ChangeEdit(
-      urlparse.urlparse(opt.host).netloc, opt.change, opt.path, data)
+      urllib.parse.urlparse(opt.host).netloc, opt.change, opt.path, data)
   logging.info(result)
   write_result(result, opt)
 
@@ -318,7 +310,7 @@
   (opt, args) = parser.parse_args(args)
 
   result = gerrit_util.PublishChangeEdit(
-      urlparse.urlparse(opt.host).netloc, opt.change, opt.notify)
+      urllib.parse.urlparse(opt.host).netloc, opt.change, opt.notify)
   logging.info(result)
   write_result(result, opt)
 
@@ -329,7 +321,7 @@
   parser.add_option('-c', '--change', type=int, help='change number')
   (opt, args) = parser.parse_args(args)
   result = gerrit_util.SubmitChange(
-      urlparse.urlparse(opt.host).netloc, opt.change)
+      urllib.parse.urlparse(opt.host).netloc, opt.change)
   logging.info(result)
   write_result(result, opt)
 
@@ -340,7 +332,7 @@
   parser.add_option('-c', '--change', type=int, help='change number')
   (opt, args) = parser.parse_args(args)
   result = gerrit_util.GetChangesSubmittedTogether(
-      urlparse.urlparse(opt.host).netloc, opt.change)
+      urllib.parse.urlparse(opt.host).netloc, opt.change)
   logging.info(result)
   write_result(result, opt)
 
@@ -351,7 +343,7 @@
   parser.add_option('--commit', dest='commit', help='commit hash')
   (opt, args) = parser.parse_args(args)
   result = gerrit_util.GetCommitIncludedIn(
-      urlparse.urlparse(opt.host).netloc, opt.project, opt.commit)
+      urllib.parse.urlparse(opt.host).netloc, opt.project, opt.commit)
   logging.info(result)
   write_result(result, opt)
 
@@ -361,11 +353,10 @@
   """Sets bot-commit+1 to a bot generated change."""
   parser.add_option('-c', '--change', type=int, help='change number')
   (opt, args) = parser.parse_args(args)
-  result = gerrit_util.SetReview(
-      urlparse.urlparse(opt.host).netloc,
-      opt.change,
-      labels={'Bot-Commit': 1},
-      ready=True)
+  result = gerrit_util.SetReview(urllib.parse.urlparse(opt.host).netloc,
+                                 opt.change,
+                                 labels={'Bot-Commit': 1},
+                                 ready=True)
   logging.info(result)
   write_result(result, opt)
 
@@ -379,7 +370,7 @@
                     nargs=2,
                     metavar=('label_name', 'label_value'))
   (opt, args) = parser.parse_args(args)
-  result = gerrit_util.SetReview(urlparse.urlparse(opt.host).netloc,
+  result = gerrit_util.SetReview(urllib.parse.urlparse(opt.host).netloc,
                                  opt.change,
                                  labels={opt.label[0]: opt.label[1]})
   logging.info(result)
@@ -395,8 +386,7 @@
   (opt, args) = parser.parse_args(args)
   assert opt.change, "-c not defined"
   result = gerrit_util.AbandonChange(
-      urlparse.urlparse(opt.host).netloc,
-      opt.change, opt.message)
+      urllib.parse.urlparse(opt.host).netloc, opt.change, opt.message)
   logging.info(result)
   write_result(result, opt)
 
@@ -439,7 +429,7 @@
   search_query.append(('status', 'open'))
   logging.info("Searching for: %s" % search_query)
 
-  host = urlparse.urlparse(opt.host).netloc
+  host = urllib.parse.urlparse(opt.host).netloc
 
   result = gerrit_util.QueryChanges(
       host,