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(
namespace_packages = ['zc'],
install_requires = [
'setuptools>=8.0',
'requests',
],
include_package_data = True,
entry_points = entry_points,
......
......@@ -31,28 +31,15 @@ try:
except ImportError:
# Python 2
import base64
from urlparse import urlparse
from urlparse import urlunparse
import urllib2
# use requests for connection pooling
import requests
session = requests.Session()
def urlretrieve(url, tmp_path):
"""Work around Python issue 24599 includig basic auth support
"""
scheme, netloc, path, params, query, frag = urlparse(url)
auth, host = urllib2.splituser(netloc)
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()
r = session.get(url)
with open(tmp_path, 'wb') as fp:
fp.write(r.content)
return tmp_path, r
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