Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_headers(self):
self.assertIsInstance(self.returned_obj.headers, email.message.Message)

def test_url(self):
self.assertEqual(self.returned_obj.url, "file://" + self.quoted_pathname)
self.assertEqual(self.returned_obj.url, "file:" + self.quoted_pathname)

def test_status(self):
self.assertIsNone(self.returned_obj.status)
Expand All @@ -165,7 +165,7 @@ def test_info(self):
self.assertIsInstance(self.returned_obj.info(), email.message.Message)

def test_geturl(self):
self.assertEqual(self.returned_obj.geturl(), "file://" + self.quoted_pathname)
self.assertEqual(self.returned_obj.geturl(), "file:" + self.quoted_pathname)

def test_getcode(self):
self.assertIsNone(self.returned_obj.getcode())
Expand Down
6 changes: 1 addition & 5 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,7 @@ def open_local_file(self, req):
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
return addinfourl(open(localfile, 'rb'), headers, origurl)
return addinfourl(open(localfile, 'rb'), headers, req.full_url)
except OSError as exp:
raise URLError(exp, exp.filename)
raise URLError('file not on local host')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix value of :attr:`urllib.response.addinfourl.url` for ``file:`` URIs that
express relative paths and absolute Windows paths. The original URL is now
used.
Loading