diff options
-rwxr-xr-x | setuptools/package_index.py | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index a0bb936d..2e0f2092 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -928,20 +928,30 @@ class PyPirc(object): """ self.dict_ = {} - if 'HOME' in os.environ: - 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 + if 'HOME' not in os.environ: + return + + rc = os.path.join(os.environ['HOME'], '.pypirc') + if not os.path.exists(rc): + return + + initial = dict.fromkeys(['username', 'password', 'repository'], '') + config = ConfigParser.ConfigParser(initial) + config.read(rc) + + sections_with_repositories = [ + section for section in config.sections() + if config.get(section, 'repository').strip() + ] + + for section in sections_with_repositories: + auth = ( + config.get(section, 'username').strip(), + config.get(section, 'password').strip(), + ) + value = '%s:%s' % auth + repo = config.get(section, 'repository').strip() + self.dict_[repo] = value def __call__(self, url): """ """ |