Revert "Drop py2 support in gerrit and git related files"
This reverts commit b5c7f4b46c3309d46e1796bce7fa83388af9bfd8.
Reason for revert: missing a replace for urlparse.urlparse
Original change's description:
> 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>
Bug: 1475402
Change-Id: Idd00fdfe0b3d62785da2789a7dfcc9fbc79b6385
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4811623
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/gerrit_util.py b/gerrit_util.py
index 1aeb94c..8312bba 100644
--- a/gerrit_util.py
+++ b/gerrit_util.py
@@ -8,6 +8,9 @@
https://gerrit-review.googlesource.com/Documentation/rest-api.html
"""
+from __future__ import print_function
+from __future__ import unicode_literals
+
import base64
import contextlib
import httplib2
@@ -30,10 +33,15 @@
import metrics_utils
import subprocess2
+from third_party import six
from six.moves import urllib
-import http.cookiejar
-from io import StringIO
+if sys.version_info.major == 2:
+ import cookielib
+ from StringIO import StringIO
+else:
+ import http.cookiejar as cookielib
+ from io import StringIO
LOGGER = logging.getLogger()
# With a starting sleep time of 12.0 seconds, x <= [1.8-2.2]x backoff, and six
@@ -247,7 +255,7 @@
def _get_auth_for_host(self, host):
for domain, creds in self.gitcookies.items():
- if http.cookiejar.domain_match(host, domain):
+ if cookielib.domain_match(host, domain):
return (creds[0], None, creds[1])
return self.netrc.authenticators(host)