aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-11-14 09:44:07 -0500
committerJason R. Coombs <jaraco@jaraco.com>2013-11-14 09:44:07 -0500
commitb79e972b8928224516e5361342c4d2f11c83fb24 (patch)
treece4b923424061976f28a774fd7f8f0cf12fa4ce3
parent3822e3e7ad8cda5012b602f7e8f52cdd44665dd3 (diff)
downloadexternal_python_setuptools-b79e972b8928224516e5361342c4d2f11c83fb24.tar.gz
external_python_setuptools-b79e972b8928224516e5361342c4d2f11c83fb24.tar.bz2
external_python_setuptools-b79e972b8928224516e5361342c4d2f11c83fb24.zip
Refactor for flatter code
-rwxr-xr-xsetuptools/package_index.py38
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):
""" """