aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2018-12-15 20:49:22 -0500
committerGitHub <noreply@github.com>2018-12-15 20:49:22 -0500
commit235dc9d7ff3073cc64332e4f985192155810be30 (patch)
tree36e3caf6ccaad3868defacdfa5bf0eef488e852e
parent361013fe78322b28a1c18f4279d8777e64ac2b58 (diff)
parent42a792c3a4047d79027f7078a72238d5fb60294b (diff)
downloadexternal_python_setuptools-235dc9d7ff3073cc64332e4f985192155810be30.tar.gz
external_python_setuptools-235dc9d7ff3073cc64332e4f985192155810be30.tar.bz2
external_python_setuptools-235dc9d7ff3073cc64332e4f985192155810be30.zip
Merge pull request #1501 from pypa/bugfix/1499-no-splituser
Remove use of splituser
-rw-r--r--changelog.d/1499.change.rst1
-rw-r--r--setuptools/package_index.py16
-rw-r--r--setuptools/tests/test_packageindex.py16
3 files changed, 27 insertions, 6 deletions
diff --git a/changelog.d/1499.change.rst b/changelog.d/1499.change.rst
new file mode 100644
index 00000000..10e4db68
--- /dev/null
+++ b/changelog.d/1499.change.rst
@@ -0,0 +1 @@
+``setuptools.package_index`` no longer relies on the deprecated ``urllib.parse.splituser`` per Python #27485.
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 1608b91a..7e9517ce 100644
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -850,13 +850,16 @@ class PackageIndex(Environment):
def _download_svn(self, url, filename):
warnings.warn("SVN download support is deprecated", UserWarning)
+ def splituser(host):
+ user, delim, host = host.rpartition('@')
+ return user, host
url = url.split('#', 1)[0] # remove any fragment for svn's sake
creds = ''
if url.lower().startswith('svn:') and '@' in url:
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)
@@ -1047,15 +1050,16 @@ 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.
if netloc.endswith(':'):
raise http_client.InvalidURL("nonnumeric port: ''")
- if scheme in ('http', 'https'):
- auth, host = urllib.parse.splituser(netloc)
+ if scheme in ('http', 'https') and parsed.username:
+ auth = ':'.join((parsed.username, parsed.password))
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, parsed.hostname, path, params, query, frag
new_url = urllib.parse.urlunparse(parts)
request = urllib.request.Request(new_url)
request.add_header("Authorization", auth)
@@ -1082,7 +1086,7 @@ 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 == parsed.hostname:
parts = s2, netloc, path2, param2, query2, frag2
fp.url = urllib.parse.urlunparse(parts)
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index 1f6bc797..b7276682 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -262,6 +262,22 @@ class TestPackageIndex:
).format(**locals())
os_system_mock.assert_called_once_with(expected)
+ def test_download_svn(self, tmpdir):
+ url = 'svn+https://svn.example/project#egg=foo'
+ index = setuptools.package_index.PackageIndex()
+
+ with mock.patch("os.system") as os_system_mock:
+ result = index.download(url, str(tmpdir))
+
+ os_system_mock.assert_called()
+
+ expected_dir = str(tmpdir / 'project')
+ expected = (
+ 'svn checkout -q '
+ 'svn+https://svn.example/project {expected_dir}'
+ ).format(**locals())
+ os_system_mock.assert_called_once_with(expected)
+
class TestContentCheckers:
def test_md5(self):