diff options
author | pje <none@none> | 2013-05-04 16:07:01 -0400 |
---|---|---|
committer | pje <none@none> | 2013-05-04 16:07:01 -0400 |
commit | 27d44ebd4ca443c9df123f308b46cc1cbd7d2404 (patch) | |
tree | a009b680f61c47161d4b99650394c78e7dc0c099 /setuptools/package_index.py | |
parent | c2488982d312b8eb577fbf7e364d0860102cf14d (diff) | |
download | external_python_setuptools-27d44ebd4ca443c9df123f308b46cc1cbd7d2404.tar.gz external_python_setuptools-27d44ebd4ca443c9df123f308b46cc1cbd7d2404.tar.bz2 external_python_setuptools-27d44ebd4ca443c9df123f308b46cc1cbd7d2404.zip |
Low-level SSL verification w/out warnings or options; automatically uses
it if it can, won't if it doesn't.
(grafted from 8dc579408781836ecf30b637665ad7f2509933a5)
--HG--
branch : setuptools-0.6
extra : source : 8dc579408781836ecf30b637665ad7f2509933a5
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1668e765..aab2bb23 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1,6 +1,6 @@ """PyPI and direct package downloading""" import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO -import httplib, urllib +import httplib, urllib; from setuptools import ssl_support from pkg_resources import * from distutils import log from distutils.errors import DistutilsError @@ -145,12 +145,11 @@ user_agent = "Python-urllib/%s setuptools/%s" % ( urllib2.__version__, require('setuptools')[0].version ) - class PackageIndex(Environment): """A distribution index that scans web pages for download URLs""" def __init__(self, index_url="https://pypi.python.org/simple", hosts=('*',), - *args, **kw + ca_bundle=None, verify_ssl=True, *args, **kw ): Environment.__init__(self,*args,**kw) self.index_url = index_url + "/"[:not index_url.endswith('/')] @@ -159,8 +158,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""" @@ -575,12 +575,13 @@ class PackageIndex(Environment): def open_url(self, url, warning=None): if url.startswith('file:'): return local_open(url) try: - return open_with_auth(url) - except urllib2.HTTPError, v: - return v - except urllib2.URLError, v: - reason = v.reason - except httplib.HTTPException, v: + return open_with_auth(url, self.opener) + except urllib2.HTTPError: + return sys.exc_info()[1] + except urllib2.URLError: + reason = sys.exc_info()[1].reason + except httplib.HTTPException: + v = sys.exc_info()[1] reason = "%s: %s" % (v.__doc__ or v.__class__.__name__, v) if warning: self.warn(warning, reason) @@ -612,7 +613,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) @@ -736,7 +736,7 @@ def htmldecode(text): -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) @@ -755,7 +755,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, |