New submission from Mike Auty <[email protected]>:
I've found open to have difficulty with a resolved pathlib path:
Example code of:
import pathlib
path = "Z:\\test.py"
with open(path) as fp:
print("Stock open: works")
data = fp.read()
with open(pathlib.Path(path).resolve().as_uri()) as fp:
print("Pathlib resolve open")
data = fp.read()
Results in:
Z:\> python test.py
Stock open: works
Traceback (most recent call last):
File "Z:\test.py", line 12, in <module>
with open(pathlib.Path(path).resolve().as_uri()) as fp:
FileNotFoundError: [Errno 2] No such file or directory:
"file://machine/share/test.py"
Interestingly, I've found that open("file:////machine/share/test.py") succeeds,
but this isn't what pathlib's resolve() produces. It appears as though
file_open only supports hosts that are local, but will open UNC paths on
windows with the additional slashes. This is quite confusing behaviour and
it's not clear why file://host/share/file won't work, but
file:////host/share/file does.
I imagine this is a long time issue and a decision has already been reached on
why file_open doesn't support such URIs, but I couldn't find the answer
anywhere, just issue 32442 which was resolved without clarifying the
situation...
----------
messages: 412602
nosy: ikelos
priority: normal
severity: normal
status: open
title: file_open doesn't handle UNC paths produced by pathlib's resolve() (but
can handle UNC paths with additional slashes)
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46654>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com