diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-14 10:08:50 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-14 10:08:50 -0500 |
commit | bf742c3f6069802d26c09118dd6c36d55634e22d (patch) | |
tree | c977af4cfbb6309e4581213a7d10a7f5ff291180 /setuptools/package_index.py | |
parent | fccf9357c484e4b475348dfbef321e544e2a3cab (diff) | |
download | external_python_setuptools-bf742c3f6069802d26c09118dd6c36d55634e22d.tar.gz external_python_setuptools-bf742c3f6069802d26c09118dd6c36d55634e22d.tar.bz2 external_python_setuptools-bf742c3f6069802d26c09118dd6c36d55634e22d.zip |
Derive PyPirc from ConfigParser for more general purpose use.
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 5f328a03..5b8dc357 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -935,34 +935,35 @@ class Credential(object): def __str__(self): return '%(username)s:%(password)s' % vars(self) -class PyPirc(object): +class PyPirc(ConfigParser.ConfigParser): def __init__(self): """ - Extract pypirc authentication information from home directory + Load from ~/.pypirc """ - self.dict_ = {} + defaults = dict.fromkeys(['username', 'password', 'repository'], '') + super(PyPirc, self).__init__(defaults) rc = os.path.join(os.path.expanduser('~'), '.pypirc') - if not os.path.exists(rc): - return - - initial = dict.fromkeys(['username', 'password', 'repository'], '') - config = ConfigParser.ConfigParser(initial) - config.read(rc) + if os.path.exists(rc): + self.read(rc) + @property + def dict_(self): + dict_ = {} sections_with_repositories = [ - section for section in config.sections() - if config.get(section, 'repository').strip() + section for section in self.sections() + if self.get(section, 'repository').strip() ] for section in sections_with_repositories: cred = Credential( - config.get(section, 'username').strip(), - config.get(section, 'password').strip(), + self.get(section, 'username').strip(), + self.get(section, 'password').strip(), ) - repo = config.get(section, 'repository').strip() - self.dict_[repo] = cred + repo = self.get(section, 'repository').strip() + dict_[repo] = cred + return dict_ def __call__(self, url): """ """ |