GH-127090: Fix urllib.response.addinfourl.url value for opened file: URIs (#127091)

The canonical `file:` URL (as generated by `pathname2url()`) is now used as the `url` attribute of the returned `addinfourl` object. The `addinfourl.url` attribute reflects the resolved URL for both `file:` or `http[s]:` URLs now.
This commit is contained in:
Barney Gale 2024-12-07 17:58:42 +00:00 committed by GitHub
parent 27d0d21413
commit 79b7cab50a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 28 deletions

View file

@ -1488,10 +1488,7 @@ class FileHandler(BaseHandler):
host, port = _splitport(host)
if not host or \
(not port and _safe_gethostbyname(host) in self.get_names()):
if host:
origurl = 'file://' + host + filename
else:
origurl = 'file://' + filename
origurl = 'file:' + pathname2url(localfile)
return addinfourl(open(localfile, 'rb'), headers, origurl)
except OSError as exp:
raise URLError(exp, exp.filename)