Commit 9299c184 authored by Stefano Mazzucco's avatar Stefano Mazzucco

Enable downloading behind a proxy by using urllib2

Behind a proxy, `urllib` does not work with Python2 due to [Python issue
24599](https://bugs.python.org/issue24599).

Instead of using `urllib`, let's implement `urlretrieve` with `urllib2`, which
instead works and leave the Python3 implementation untouched (since that
one works too).

This fixes buildout issue #32.

There's no need to change the `try: except:IOError` block where `urlretrieve` is
used (line 195 in download.py) since the exceptions raised by `urllib2`
are subclasses of `IOError` and will then be caught.
parent 5edae50d
......@@ -22,17 +22,26 @@ try:
# Python 3
from urllib.request import FancyURLopener, URLopener, urlretrieve
from urllib.parse import urlparse
from urllib import request as urllib # for monkey patch below :(
from urllib import request
class URLOpener(FancyURLopener):
http_error_default = URLopener.http_error_default
request._urlopener = URLOpener() # Ook! Monkey patch!
except ImportError:
# Python 2
from urllib import FancyURLopener, URLopener, urlretrieve
from urlparse import urlparse
import urllib
class URLOpener(FancyURLopener):
http_error_default = URLopener.http_error_default
import urllib2
urllib._urlopener = URLOpener() # Ook! Monkey patch!
def urlretrieve(url, path):
"""Work around Python issue 24599
"""
url_obj = urllib2.urlopen(url)
with open(path, 'wb') as fp:
fp.write(url_obj.read())
return path, url_obj.info()
from zc.buildout.easy_install import realpath
......@@ -45,6 +54,7 @@ import sys
import tempfile
import zc.buildout
class ChecksumError(zc.buildout.UserError):
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment