diff options
author | Kai Hoppert <kai.hoppert@online.de> | 2013-08-10 18:24:23 +0200 |
---|---|---|
committer | Kai Hoppert <kai.hoppert@online.de> | 2013-08-10 18:24:23 +0200 |
commit | f051b3d36871ccd9f0f5fc770047c497f196547a (patch) | |
tree | 976fb0f75596c39197463688124c5256ec27b608 /setuptools/package_index.py | |
parent | e29ad44c0a1e8025c154c9afb4418f143019379f (diff) | |
download | external_python_setuptools-f051b3d36871ccd9f0f5fc770047c497f196547a.tar.gz external_python_setuptools-f051b3d36871ccd9f0f5fc770047c497f196547a.tar.bz2 external_python_setuptools-f051b3d36871ccd9f0f5fc770047c497f196547a.zip |
Added .pypirc authentication support for getting eggs
--HG--
extra : histedit_source : ebdc22b1f156f8af40265c5772addcfda6ae11d8
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 9c9d76a1..ca228997 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -6,6 +6,8 @@ import shutil import socket import base64 +import ConfigParser + from pkg_resources import ( CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST, require, Environment, find_distributions, safe_name, safe_version, @@ -918,6 +920,37 @@ def _encode_auth(auth): # strip the trailing carriage return return encoded.rstrip() +class PyPirc: + + def __init__(self): + """ + Extract pypirc authentication information from home directory + """ + self.dict_ = {} + + if os.environ.has_key('HOME'): + rc = os.path.join(os.environ['HOME'], '.pypirc') + if os.path.exists(rc): + config = ConfigParser.ConfigParser({ + 'username' : '', + 'password' : '', + 'repository' : ''}) + config.read(rc) + + for section in config.sections(): + if config.get(section, 'repository').strip(): + value = '%s:%s'%(config.get(section, 'username').strip(), + config.get(section, 'password').strip()) + self.dict_[config.get(section, 'repository').strip()] = value + + def __call__(self, url): + """ """ + for base_url, auth in self.dict_.items(): + if url.startswith(base_url): + return auth + + + def open_with_auth(url, opener=urllib2.urlopen): """Open a urllib2 request, handling HTTP authentication""" @@ -933,6 +966,10 @@ def open_with_auth(url, opener=urllib2.urlopen): else: auth = None + if not auth: + auth = PyPirc()(url) + log.info('Authentication found for URL: %s'%url) + if auth: auth = "Basic " + _encode_auth(auth) new_url = urlunparse((scheme,host,path,params,query,frag)) |