aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/package_index.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-06-18 08:44:39 -0500
committerJason R. Coombs <jaraco@jaraco.com>2013-06-18 08:44:39 -0500
commitfb8c7cf0abc9ce58b8a6f0621c0a9909fb9b8eff (patch)
tree95cae06260f49e011fc045000fc1531dbc0e0cf5 /setuptools/package_index.py
parent32ba6930fa97bbeac9392cac3ed49aac87fd1018 (diff)
parentdb678072da41b75408680dab3e23c1b76573bf1d (diff)
downloadexternal_python_setuptools-fb8c7cf0abc9ce58b8a6f0621c0a9909fb9b8eff.tar.gz
external_python_setuptools-fb8c7cf0abc9ce58b8a6f0621c0a9909fb9b8eff.tar.bz2
external_python_setuptools-fb8c7cf0abc9ce58b8a6f0621c0a9909fb9b8eff.zip
Merge with upstream
--HG-- branch : distribute
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-xsetuptools/package_index.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 589dade6..2cab63c1 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -1,5 +1,6 @@
"""PyPI and direct package downloading"""
import sys, os.path, re, shutil, random, socket
+import base64
from pkg_resources import *
from distutils import log
from distutils.errors import DistutilsError
@@ -201,7 +202,7 @@ class PackageIndex(Environment):
return
self.info("Reading %s", url)
- f = self.open_url(url, "Download error: %s -- Some packages may not be found!")
+ f = self.open_url(url, "Download error on %s: %%s -- Some packages may not be found!" % url)
if f is None: return
self.fetched_urls[url] = self.fetched_urls[f.url] = True
@@ -764,19 +765,41 @@ def socket_timeout(timeout=15):
return _socket_timeout
return _socket_timeout
+def _encode_auth(auth):
+ """
+ A function compatible with Python 2.3-3.3 that will encode
+ auth from a URL suitable for an HTTP header.
+ >>> _encode_auth('username%3Apassword')
+ u'dXNlcm5hbWU6cGFzc3dvcmQ='
+ """
+ auth_s = unquote(auth)
+ # convert to bytes
+ auth_bytes = auth_s.encode()
+ # use the legacy interface for Python 2.3 support
+ encoded_bytes = base64.encodestring(auth_bytes)
+ # convert back to a string
+ encoded = encoded_bytes.decode()
+ # strip the trailing carriage return
+ return encoded.rstrip()
def open_with_auth(url):
"""Open a urllib2 request, handling HTTP authentication"""
scheme, netloc, path, params, query, frag = urlparse(url)
+ # Double scheme does not raise on Mac OS X as revealed by a
+ # failing test. We would expect "nonnumeric port". Refs #20.
+ if sys.platform == 'darwin':
+ if netloc.endswith(':'):
+ raise httplib.InvalidURL("nonnumeric port: ''")
+
if scheme in ('http', 'https'):
auth, host = splituser(netloc)
else:
auth = None
if auth:
- auth = "Basic " + unquote(auth).encode('base64').strip()
+ auth = "Basic " + _encode_auth(auth)
new_url = urlunparse((scheme,host,path,params,query,frag))
request = urllib2.Request(new_url)
request.add_header("Authorization", auth)