Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63b5aed

Browse files
authoredMar 19, 2025
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.
1 parent 75103d9 commit 63b5aed

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed
 

‎Lib/pathlib/__init__.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -1271,21 +1271,8 @@ def from_uri(cls, uri):
12711271
"""Return a new path from the given 'file' URI."""
12721272
if not uri.startswith('file:'):
12731273
raise ValueError(f"URI does not start with 'file:': {uri!r}")
1274-
path = uri[5:]
1275-
if path[:3] == '///':
1276-
# Remove empty authority
1277-
path = path[2:]
1278-
elif path[:12] == '//localhost/':
1279-
# Remove 'localhost' authority
1280-
path = path[11:]
1281-
if path[:3] == '///' or (path[:1] == '/' and path[2:3] in ':|'):
1282-
# Remove slash before DOS device/UNC path
1283-
path = path[1:]
1284-
if path[1:2] == '|':
1285-
# Replace bar with colon in DOS drive
1286-
path = path[:1] + ':' + path[2:]
1287-
from urllib.parse import unquote_to_bytes
1288-
path = cls(os.fsdecode(unquote_to_bytes(path)))
1274+
from urllib.request import url2pathname
1275+
path = cls(url2pathname(uri.removeprefix('file:')))
12891276
if not path.is_absolute():
12901277
raise ValueError(f"URI is not absolute: {uri!r}")
12911278
return path

0 commit comments

Comments
 (0)
Failed to load comments.