Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,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", "")

Expand Down
4 changes: 2 additions & 2 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ def send_head(self):
if not parts.path.endswith(('/', '%2f', '%2F')):
# redirect browser - doing basically what apache does
self.send_response(HTTPStatus.MOVED_PERMANENTLY)
new_parts = (parts[0], parts[1], parts[2] + '/',
parts[3], parts[4])
new_parts = (parts.scheme, parts.netloc, parts.path + '/',
parts.query, parts.fragment)
new_url = urllib.parse.urlunsplit(new_parts)
self.send_header("Location", new_url)
self.send_header("Content-Length", "0")
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/ssl_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 9 additions & 7 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")

Expand Down Expand Up @@ -832,11 +832,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
Expand Down Expand Up @@ -1209,7 +1209,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()
Expand Down Expand Up @@ -1668,7 +1668,9 @@ def url2pathname(url, *, require_scheme=False, resolve_host=False):
"""
if not require_scheme:
url = 'file:' + url
scheme, authority, url = urlsplit(url)[:3] # Discard query and fragment.
parts = urlsplit(url)
# Discard query and fragment.
scheme, authority, url = parts.scheme, parts.netloc, parts.path
if scheme != 'file':
raise URLError("URL is missing a 'file:' scheme")
if os.name == 'nt':
Expand Down
4 changes: 3 additions & 1 deletion Lib/urllib/robotparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion Lib/xmlrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ def __init__(self, uri, transport=None, encoding=None, verbose=False,
if p.scheme not in ("http", "https"):
raise OSError("unsupported XML-RPC protocol")
self.__host = p.netloc
self.__handler = urllib.parse.urlunsplit(["", "", *p[2:]])
self.__handler = urllib.parse.urlunsplit(["", "", p.path, p.query, p.fragment])
if not self.__handler:
self.__handler = "/RPC2"

Expand Down
Loading