Commit da71a8ed authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Julien Muchembled

download: don't use splitport and splituser

They are deprecated since Python 3.8

Rebase instructions:
- split and fixup commits
    171c2459
    c9e9b267
parent 2789ebd1
...@@ -21,13 +21,13 @@ except ImportError: ...@@ -21,13 +21,13 @@ except ImportError:
try: try:
# Python 3 # Python 3
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import Request, splitport, splituser, urlopen from urllib.request import Request, urlopen
from urllib.parse import urlparse, urlunparse from urllib.parse import urlparse, urlunparse
except ImportError: except ImportError:
# Python 2 # Python 2
from urlparse import urlparse from urlparse import urlparse
from urlparse import urlunparse from urlparse import urlunparse
from urllib2 import HTTPError, Request, splitport, splituser, urlopen from urllib2 import HTTPError, Request, urlopen
from zc.buildout.easy_install import realpath from zc.buildout.easy_install import realpath
from base64 import b64encode from base64 import b64encode
...@@ -271,14 +271,15 @@ class Download(object): ...@@ -271,14 +271,15 @@ class Download(object):
return '%s:%s' % (url_host, url_port) return '%s:%s' % (url_host, url_port)
def urlretrieve(self, url, tmp_path): def urlretrieve(self, url, tmp_path):
scheme, netloc, path, params, query, frag = urlparse(url) parsed_url = urlparse(url)
req = url req = url
while scheme in ('http', 'https'): # not a loop while parsed_url.scheme in ('http', 'https'): # not a loop
auth, host = splituser(netloc) auth_host = parsed_url.netloc.rsplit('@', 1)
if auth: if len(auth_host) > 1:
url = urlunparse((scheme, host, path, params, query, frag)) auth = auth_host[0]
url = parsed_url._replace(netloc=auth_host[1]).geturl()
else: else:
auth = netrc.authenticators(splitport(host)[0]) auth = netrc.authenticators(parsed_url.hostname)
if not auth: if not auth:
break break
auth = '{0}:{2}'.format(*auth) auth = '{0}:{2}'.format(*auth)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment