https://github.com/python/cpython/commit/63b5aed06ed6fcd7956c9b99eb0a3651116cf2e4
commit: 63b5aed06ed6fcd7956c9b99eb0a3651116cf2e4
branch: main
author: Barney Gale <[email protected]>
committer: barneygale <[email protected]>
date: 2025-03-19T21:08:32Z
summary:
GH-123599: Remove duplicate `url2pathname()` implementation (#127237)
Call `urllib.request.url2pathname()` from `pathlib.Path.from_uri()` rather
than re-implementing it. This paves the way for solving the main issue
(ignoring local authorities and rejecting non-local ones) in urllib, not
pathlib.
files:
M Lib/pathlib/__init__.py
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py
index c272ac4dddd40d..f44283a53e5704 100644
--- a/Lib/pathlib/__init__.py
+++ b/Lib/pathlib/__init__.py
@@ -1271,21 +1271,8 @@ def from_uri(cls, uri):
"""Return a new path from the given 'file' URI."""
if not uri.startswith('file:'):
raise ValueError(f"URI does not start with 'file:': {uri!r}")
- path = uri[5:]
- if path[:3] == '///':
- # Remove empty authority
- path = path[2:]
- elif path[:12] == '//localhost/':
- # Remove 'localhost' authority
- path = path[11:]
- if path[:3] == '///' or (path[:1] == '/' and path[2:3] in ':|'):
- # Remove slash before DOS device/UNC path
- path = path[1:]
- if path[1:2] == '|':
- # Replace bar with colon in DOS drive
- path = path[:1] + ':' + path[2:]
- from urllib.parse import unquote_to_bytes
- path = cls(os.fsdecode(unquote_to_bytes(path)))
+ from urllib.request import url2pathname
+ path = cls(url2pathname(uri.removeprefix('file:')))
if not path.is_absolute():
raise ValueError(f"URI is not absolute: {uri!r}")
return path
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]