diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py index 144db91a0f0317..5c5dc78b064885 100644 --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -627,7 +627,7 @@ def request_host(request): """ url = request.get_full_url() - host = urllib.parse.urlparse(url)[1] + host = urllib.parse.urlparse(url).netloc if host == "": host = request.get_header("Host", "") diff --git a/Lib/test/ssl_servers.py b/Lib/test/ssl_servers.py index 15b071e04dda1f..e3416a822f6525 100644 --- a/Lib/test/ssl_servers.py +++ b/Lib/test/ssl_servers.py @@ -61,7 +61,7 @@ def translate_path(self, path): """ # abandon query parameters - path = urllib.parse.urlparse(path)[2] + path = urllib.parse.urlparse(path).path path = os.path.normpath(urllib.parse.unquote(path)) words = path.split('/') words = filter(None, words) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index be71575a6ea06a..1c28af08988d9f 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -868,7 +868,7 @@ def open_urlresource(url, *args, **kw): check = kw.pop('check', None) - filename = urllib.parse.urlparse(url)[2].split('/')[-1] # '/': it's URL! + filename = urllib.parse.urlparse(url).path.split('/')[-1] # '/': it's URL! fn = os.path.join(TEST_DATA_DIR, filename) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 9fa92659a255ed..59ed4a7140d59c 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -274,7 +274,7 @@ def request_host(request): """ url = request.full_url - host = urlparse(url)[1] + host = urlparse(url).netloc if host == "": host = request.get_header("Host", "") @@ -833,11 +833,11 @@ def reduce_uri(self, uri, default_port=True): """Accept authority or URI and extract only the authority and path.""" # note HTTP URLs do not have a userinfo component parts = urlsplit(uri) - if parts[1]: + if parts.netloc: # URI - scheme = parts[0] - authority = parts[1] - path = parts[2] or '/' + scheme = parts.scheme + authority = parts.netloc + path = parts.path or '/' else: # host or host:port scheme = None @@ -1222,7 +1222,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): handler_order = 490 # before Basic auth def http_error_401(self, req, fp, code, msg, headers): - host = urlparse(req.full_url)[1] + host = urlparse(req.full_url).netloc retry = self.http_error_auth_reqed('www-authenticate', host, req, headers) self.reset_retry_count() diff --git a/Lib/urllib/robotparser.py b/Lib/urllib/robotparser.py index 8d0311d96f5e0b..985333c7100438 100644 --- a/Lib/urllib/robotparser.py +++ b/Lib/urllib/robotparser.py @@ -62,7 +62,9 @@ def set_url(self, url): if isinstance(url, urllib.request.Request): url = url.full_url - self.host, self.path = urllib.parse.urlsplit(url)[1:3] + parts = urllib.parse.urlsplit(url) + self.host = parts.netloc + self.path = parts.path def read(self): """Reads the robots.txt URL and feeds it to the parser."""