From 426f69b485fd75b4659f7cf2d675ff18c1c333b7 Mon Sep 17 00:00:00 2001 From: "joshua.lock@intel.com" Date: Thu, 2 Aug 2012 23:41:49 +0000 Subject: [PATCH] Remove the use of urllib for SSL connections Using urllib for SSL connections when behind a proxy is known to be broken. Upstream has fixed this in urllib2 in Python 2.6.3 and newer so replace uses of urllib for SSL connections with urllib2 methods. R=maruel@chromium.org BUG=134165 TEST=gclient sync behind corporate proxy. Submitting this CL with git_cl. Review URL: https://chromiumcodereview.appspot.com/10825107 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@149742 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 10 ++++++++-- tests/git_cl_test.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/git_cl.py b/git_cl.py index 143ad2854d..9716ef1258 100755 --- a/git_cl.py +++ b/git_cl.py @@ -16,7 +16,6 @@ import stat import sys import textwrap import urlparse -import urllib import urllib2 try: @@ -756,6 +755,13 @@ def LoadCodereviewSettingsFromFile(fileobj): keyvals['ORIGIN_URL_CONFIG']]) +def urlretrieve(source, destination): + """urllib is broken for SSL connections via a proxy therefore we + can't use urllib.urlretrieve().""" + with open(destination, 'w') as f: + f.write(urllib2.urlopen(source).read()) + + def DownloadHooks(force): """downloads hooks @@ -773,7 +779,7 @@ def DownloadHooks(force): return os.remove(dst) try: - urllib.urlretrieve(src, dst) + urlretrieve(src, dst) os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) except Exception: if os.path.exists(dst): diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 0c3736e23c..0a916c7d81 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -431,7 +431,7 @@ class TestGitCl(TestCase): # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, 'exists', Exists) - self.mock(git_cl.urllib, 'urlretrieve', self._mocked_call) + self.mock(git_cl, 'urlretrieve', self._mocked_call) self.calls = [ ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''),