[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty
Mike Auty added the comment: I can confirm that url2pathname work with either number of slashes, and that open_file appears to have had the file: removed. However, in even if the check in open_file were bypassed, it calls open_local_file, which then strips any host before calling

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Barney Gale
Barney Gale added the comment: urllib uses nturl2path under the hood. On my system it seems to return reasonable results for both two and four leading slashes: >>> nturl2path.url2pathname('host/share/test.py') 'host\\share\\test.py' >>>

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Eryk Sun
Change by Eryk Sun : -- Removed message: https://bugs.python.org/msg412604 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty
Mike Auty added the comment: Here's the revised code sample: import pathlib import urllib.request path = "Z:\\test.py" print(f"Stock open: {pathlib.Path(path).as_uri()}") with urllib.request.urlopen(pathlib.Path(path).as_uri()) as fp: data = fp.read()

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty
Mike Auty added the comment: My bad, sorry, I realized I was conflating open with urllib.request.urlopen. I believe the issue still exists though, sorry for the confusion. -- ___ Python tracker

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty
Mike Auty added the comment: > Why are you adding `.as_uri()`? The API we provide accepts URIs, so whilst the example seems a little contrived, the code itself expects a URI and then calls open (making use of the ability to add open handlers). > Builtin open() calls C open(). As best I

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Eryk Sun
Eryk Sun added the comment: Builtin open() calls C open(). This C function supports whatever path types are supported natively. In Windows, C open() calls WinAPI CreateFileW(), which does not support "file://" URIs. The Windows API handles it as a relative path, which gets resolved against

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Barney Gale
Barney Gale added the comment: Why are you adding `.as_uri()`? -- nosy: +barneygale ___ Python tracker ___ ___ Python-bugs-list

[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty
New submission from Mike Auty : 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())