diff --git a/git_cl.py b/git_cl.py index 143ad2854..9716ef125 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 0c3736e23..0a916c7d8 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'],), ''),