Skip to content

Commit ff62541

Browse files
authored
Drop dead and half-broken redirect handling from function "_download" (#205)
Apparently urllib.request.urlopen is already following redirects for us, and "return _download(location)" was (1) not forwarding flag "binary" and (2) not supporting non-absolute URIs without a scheme.
1 parent e1cae1c commit ff62541

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

hashin.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,7 @@ def _download(url, binary=False):
6666

6767
# Note that urlopen will, by default, follow redirects.
6868
status_code = r.getcode()
69-
if 301 <= status_code < 400:
70-
location = r.headers.get("location", "")
71-
if not location:
72-
raise PackageError(
73-
"No 'Location' header on {0} ({1})".format(url, status_code)
74-
)
75-
return _download(location)
76-
elif status_code == 404:
69+
if status_code == 404:
7770
raise PackageNotFoundError(url)
7871
elif status_code != 200:
7972
raise PackageError("Download error. {0} on {1}".format(status_code, url))

tests/test_cli.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -1268,13 +1268,6 @@ def mocked_get(url, **options):
12681268
# Note that the name "Hash-in" redirects to a name that is not only
12691269
# different case, it's also spelled totally differently.
12701270
if url == "https://pypi.org/pypi/Hash-in/json":
1271-
return _Response(
1272-
"",
1273-
status_code=301,
1274-
headers={"location": "https://pypi.org/pypi/hashin/json"},
1275-
)
1276-
1277-
if url == "https://pypi.org/pypi/hashin/json":
12781271
return _Response(
12791272
{
12801273
"info": {"version": "0.10", "name": "hashin"},
@@ -1699,19 +1692,10 @@ def test_run_update_all(murlopen, tmpfile):
16991692
requirements file, and check with pypi.org if there's a new version."""
17001693

17011694
def mocked_get(url, **options):
1702-
if url == "https://pypi.org/pypi/HAShin/json":
1703-
return _Response(
1704-
"",
1705-
status_code=301,
1706-
headers={"location": "https://pypi.org/pypi/hashin/json"},
1707-
)
1708-
elif url == "https://pypi.org/pypi/hashIN/json":
1709-
return _Response(
1710-
"",
1711-
status_code=301,
1712-
headers={"location": "https://pypi.org/pypi/hashin/json"},
1713-
)
1714-
elif url == "https://pypi.org/pypi/hashin/json":
1695+
if url in (
1696+
"https://pypi.org/pypi/HAShin/json",
1697+
"https://pypi.org/pypi/hashIN/json",
1698+
):
17151699
return _Response(
17161700
{
17171701
"info": {"version": "0.11", "name": "hashin"},

0 commit comments

Comments
 (0)