Improve gclient Python 3 compatibility

This enables gclient sync and gclient runhooks to run, barring hook script failures.
git cl upload also now works.

The scripts still work with Python 2.
There are no intended behaviour changes.

Bug: 942522
Change-Id: I2ac587b5f803ba7f5bb5e412337ce049f4b1a741
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1524583
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
diff --git a/gsutil.py b/gsutil.py
index 8bfed54..55e4cb0 100755
--- a/gsutil.py
+++ b/gsutil.py
@@ -17,7 +17,12 @@
 import sys
 import tempfile
 import time
-import urllib2
+
+try:
+  import urllib2 as urllib
+except ImportError:  # For Py3 compatibility
+  import urllib.request as urllib
+
 import zipfile
 
 
@@ -53,7 +58,7 @@
     local_md5 = md5_calc.hexdigest()
 
     metadata_url = '%s%s' % (API_URL, filename)
-    metadata = json.load(urllib2.urlopen(metadata_url))
+    metadata = json.load(urllib.urlopen(metadata_url))
     remote_md5 = base64.b64decode(metadata['md5Hash'])
 
     if local_md5 == remote_md5:
@@ -62,7 +67,7 @@
 
   # Do the download.
   url = '%s%s' % (GSUTIL_URL, filename)
-  u = urllib2.urlopen(url)
+  u = urllib.urlopen(url)
   with open(target_filename, 'wb') as f:
     while True:
       buf = u.read(4096)