diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-03-21 05:55:44 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-03-21 05:55:44 -0400 |
| commit | cfbefe5715e31db3c8cac70f7a1cd1c16fd4b5a7 (patch) | |
| tree | 1551248b2a29b34b26388ea68fe994854f3e84e2 /setuptools/package_index.py | |
| parent | 7843688bc33dd4e13e10130bc49da4c290fe7d7f (diff) | |
| parent | 060445bfb557a1d0f6b726716dafa6bacaa44c34 (diff) | |
| download | python-setuptools-git-cfbefe5715e31db3c8cac70f7a1cd1c16fd4b5a7.tar.gz | |
Merge branch 'master' into jorikdima-master
Diffstat (limited to 'setuptools/package_index.py')
| -rw-r--r-- | setuptools/package_index.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1608b91a..7a802413 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -46,7 +46,8 @@ __all__ = [ _SOCKET_TIMEOUT = 15 _tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}" -user_agent = _tmpl.format(py_major=sys.version[:3], setuptools=setuptools) +user_agent = _tmpl.format( + py_major='{}.{}'.format(*sys.version_info), setuptools=setuptools) def parse_requirement_arg(spec): @@ -348,6 +349,8 @@ class PackageIndex(Environment): f = self.open_url(url, tmpl % url) if f is None: return + if isinstance(f, urllib.error.HTTPError) and f.code == 401: + self.info("Authentication error: %s" % f.msg) self.fetched_urls[f.url] = True if 'html' not in f.headers.get('content-type', '').lower(): f.close() # not html, we can't process it @@ -856,7 +859,7 @@ class PackageIndex(Environment): scheme, netloc, path, p, q, f = urllib.parse.urlparse(url) if not netloc and path.startswith('//') and '/' in path[2:]: netloc, path = path[2:].split('/', 1) - auth, host = urllib.parse.splituser(netloc) + auth, host = _splituser(netloc) if auth: if ':' in auth: user, pw = auth.split(':', 1) @@ -897,7 +900,7 @@ class PackageIndex(Environment): if rev is not None: self.info("Checking out %s", rev) - os.system("(cd %s && git checkout --quiet %s)" % ( + os.system("git -C %s checkout --quiet %s" % ( filename, rev, )) @@ -913,7 +916,7 @@ class PackageIndex(Environment): if rev is not None: self.info("Updating to %s", rev) - os.system("(cd %s && hg up -C -r %s -q)" % ( + os.system("hg --cwd %s up -C -r %s -q" % ( filename, rev, )) @@ -1047,7 +1050,8 @@ class PyPIConfig(configparser.RawConfigParser): def open_with_auth(url, opener=urllib.request.urlopen): """Open a urllib2 request, handling HTTP authentication""" - scheme, netloc, path, params, query, frag = urllib.parse.urlparse(url) + parsed = urllib.parse.urlparse(url) + scheme, netloc, path, params, query, frag = parsed # Double scheme does not raise on Mac OS X as revealed by a # failing test. We would expect "nonnumeric port". Refs #20. @@ -1055,7 +1059,7 @@ def open_with_auth(url, opener=urllib.request.urlopen): raise http_client.InvalidURL("nonnumeric port: ''") if scheme in ('http', 'https'): - auth, host = urllib.parse.splituser(netloc) + auth, address = _splituser(netloc) else: auth = None @@ -1068,7 +1072,7 @@ def open_with_auth(url, opener=urllib.request.urlopen): if auth: auth = "Basic " + _encode_auth(auth) - parts = scheme, host, path, params, query, frag + parts = scheme, address, path, params, query, frag new_url = urllib.parse.urlunparse(parts) request = urllib.request.Request(new_url) request.add_header("Authorization", auth) @@ -1082,13 +1086,21 @@ def open_with_auth(url, opener=urllib.request.urlopen): # Put authentication info back into request URL if same host, # so that links found on the page will work s2, h2, path2, param2, query2, frag2 = urllib.parse.urlparse(fp.url) - if s2 == scheme and h2 == host: + if s2 == scheme and h2 == address: parts = s2, netloc, path2, param2, query2, frag2 fp.url = urllib.parse.urlunparse(parts) return fp +# copy of urllib.parse._splituser from Python 3.8 +def _splituser(host): + """splituser('user[:passwd]@host[:port]') + --> 'user[:passwd]', 'host[:port]'.""" + user, delim, host = host.rpartition('@') + return (user if delim else None), host + + # adding a timeout to avoid freezing package_index open_with_auth = socket_timeout(_SOCKET_TIMEOUT)(open_with_auth) |
