aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/package_index.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-11-14 09:52:58 -0500
committerJason R. Coombs <jaraco@jaraco.com>2013-11-14 09:52:58 -0500
commite405a2b4861216e3c6b50c79f7b26289656fdb41 (patch)
tree9247ed231cc1a665299c885935c5a287e6b790ef /setuptools/package_index.py
parentb79e972b8928224516e5361342c4d2f11c83fb24 (diff)
downloadexternal_python_setuptools-e405a2b4861216e3c6b50c79f7b26289656fdb41.tar.gz
external_python_setuptools-e405a2b4861216e3c6b50c79f7b26289656fdb41.tar.bz2
external_python_setuptools-e405a2b4861216e3c6b50c79f7b26289656fdb41.zip
Extract 'Credential' class for representing a username/password credential
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-xsetuptools/package_index.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 2e0f2092..3154eccb 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -920,6 +920,21 @@ def _encode_auth(auth):
# strip the trailing carriage return
return encoded.rstrip()
+class Credential(object):
+ """
+ A username/password pair. Use like a namedtuple.
+ """
+ def __init__(self, username, password):
+ self.username = username
+ self.password = password
+
+ def __iter__(self):
+ yield self.username
+ yield self.password
+
+ def __str__(self):
+ return '%(username)s:%(password)s' % vars(self)
+
class PyPirc(object):
def __init__(self):
@@ -945,13 +960,12 @@ class PyPirc(object):
]
for section in sections_with_repositories:
- auth = (
+ cred = Credential(
config.get(section, 'username').strip(),
config.get(section, 'password').strip(),
)
- value = '%s:%s' % auth
repo = config.get(section, 'repository').strip()
- self.dict_[repo] = value
+ self.dict_[repo] = cred
def __call__(self, url):
""" """
@@ -976,7 +990,7 @@ def open_with_auth(url, opener=urllib2.urlopen):
auth = None
if not auth:
- auth = PyPirc()(url)
+ auth = str(PyPirc()(url))
log.info('Authentication found for URL: %s' % url)
if auth: