diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-13 07:37:46 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-13 07:37:46 -0400 |
commit | 522dd17075958cf71ed30aada3eaccdb29a9c488 (patch) | |
tree | adae4b789a1348b0ce526776b83e5613d14643c1 /setuptools/package_index.py | |
parent | 8f05565451ef38cc10074582ad826941f8f8c899 (diff) | |
parent | 430529414dec7264d11400d2c1bd8a207ee76904 (diff) | |
download | external_python_setuptools-522dd17075958cf71ed30aada3eaccdb29a9c488.tar.gz external_python_setuptools-522dd17075958cf71ed30aada3eaccdb29a9c488.tar.bz2 external_python_setuptools-522dd17075958cf71ed30aada3eaccdb29a9c488.zip |
Merged latest changes from setuptools-0.6 branch
--HG--
rename : doc/formats.txt => docs/formats.txt
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 3a6b6fac..04a30a45 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -2,6 +2,7 @@ import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO import base64 import httplib, urllib +from setuptools import ssl_support from pkg_resources import * from distutils import log from distutils.errors import DistutilsError @@ -157,12 +158,11 @@ user_agent = "Python-urllib/%s setuptools/%s" % ( sys.version[:3], require('setuptools')[0].version ) - class PackageIndex(Environment): """A distribution index that scans web pages for download URLs""" - def __init__(self, index_url="http://pypi.python.org/simple", hosts=('*',), - *args, **kw + def __init__(self, index_url="https://pypi.python.org/simple", hosts=('*',), + ca_bundle=None, verify_ssl=True, *args, **kw ): Environment.__init__(self,*args,**kw) self.index_url = index_url + "/"[:not index_url.endswith('/')] @@ -171,8 +171,9 @@ class PackageIndex(Environment): self.package_pages = {} self.allows = re.compile('|'.join(map(translate,hosts))).match self.to_scan = [] - - + if verify_ssl and ssl_support.is_available and (ca_bundle or ssl_support.find_ca_bundle()): + self.opener = ssl_support.opener_for(ca_bundle) + else: self.opener = urllib2.urlopen def process_url(self, url, retrieve=False): """Evaluate a URL as a possible download, and maybe retrieve it""" @@ -601,7 +602,7 @@ class PackageIndex(Environment): if url.startswith('file:'): return local_open(url) try: - return open_with_auth(url) + return open_with_auth(url, self.opener) except (ValueError, httplib.InvalidURL), v: msg = ' '.join([str(arg) for arg in v.args]) if warning: @@ -659,7 +660,6 @@ class PackageIndex(Environment): self.url_ok(url, True) # raises error if not allowed return self._attempt_download(url, filename) - def scan_url(self, url): self.process_url(url, True) @@ -859,7 +859,7 @@ def _encode_auth(auth): # strip the trailing carriage return return encoded.rstrip() -def open_with_auth(url): +def open_with_auth(url, opener=urllib2.urlopen): """Open a urllib2 request, handling HTTP authentication""" scheme, netloc, path, params, query, frag = urlparse.urlparse(url) @@ -883,7 +883,7 @@ def open_with_auth(url): request = urllib2.Request(url) request.add_header('User-Agent', user_agent) - fp = urllib2.urlopen(request) + fp = opener(request) if auth: # Put authentication info back into request URL if same host, |