diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-12-07 17:58:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-07 17:58:42 (GMT) |
commit | 79b7cab50a3292a1c01466cf0e69fb7b4e56cfb1 (patch) | |
tree | 19605ae130fee6d42c311f29ae51ea1c3887593f /Lib/urllib | |
parent | 27d0d2141319d82709eb09ba20065df3e1714fab (diff) | |
download | cpython-79b7cab50a3292a1c01466cf0e69fb7b4e56cfb1.zip cpython-79b7cab50a3292a1c01466cf0e69fb7b4e56cfb1.tar.gz cpython-79b7cab50a3292a1c01466cf0e69fb7b4e56cfb1.tar.bz2 |
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.
Diffstat (limited to 'Lib/urllib')
-rw-r--r-- | Lib/urllib/request.py | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 1fcaa89..7ef8543 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -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) |