Commit f7ac1f45 authored by Jérome Perrin's avatar Jérome Perrin

download: use requests session to enable connection pooling

parent 3f32153f
...@@ -89,6 +89,7 @@ setup( ...@@ -89,6 +89,7 @@ setup(
namespace_packages = ['zc'], namespace_packages = ['zc'],
install_requires = [ install_requires = [
'setuptools>=8.0', 'setuptools>=8.0',
'requests',
], ],
include_package_data = True, include_package_data = True,
entry_points = entry_points, entry_points = entry_points,
......
...@@ -31,28 +31,15 @@ try: ...@@ -31,28 +31,15 @@ try:
except ImportError: except ImportError:
# Python 2 # Python 2
import base64
from urlparse import urlparse from urlparse import urlparse
from urlparse import urlunparse # use requests for connection pooling
import urllib2 import requests
session = requests.Session()
def urlretrieve(url, tmp_path): def urlretrieve(url, tmp_path):
"""Work around Python issue 24599 includig basic auth support r = session.get(url)
""" with open(tmp_path, 'wb') as fp:
scheme, netloc, path, params, query, frag = urlparse(url) fp.write(r.content)
auth, host = urllib2.splituser(netloc) return tmp_path, r
if auth:
url = urlunparse((scheme, host, path, params, query, frag))
req = urllib2.Request(url)
base64string = base64.encodestring(auth)[:-1]
basic = "Basic " + base64string
req.add_header("Authorization", basic)
else:
req = urllib2.Request(url)
url_obj = urllib2.urlopen(req)
with open(tmp_path, 'wb') as fp:
fp.write(url_obj.read())
return tmp_path, url_obj.info()
from zc.buildout.easy_install import realpath from zc.buildout.easy_install import realpath
......
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