Eryk Sun <eryk...@gmail.com> added the comment:

> "http:" isn't a valid drive letter, I'd imagine.

It's not a valid DOS drive, but that's not the problem. "http://w.org"; is 
parsed as a relative path. The double slashes are replaced by a single 
backslash, and the Windows API tries to open the path relative to a handle for 
the current working directory. 

The issue is handling a path component named "http:". Some filesystems such as 
FAT32 reserve ":" as an invalid name character. Others such as NTFS and ReFS 
reserve ":" as the stream delimiter [1], and "http:" is not a valid stream 
name. I'm on the fence about how to handle names that the OS rejects as invalid 
in a boolean context (e.g. exists, isfile, etc). In one sense, returning False 
is reasonable because an invalid name cannot exist. But on the other hand, 
asking whether something that's invalid exists is a nonsense question that 
warrants an exception. That said, the issue has already been decided multiple 
times in favor of returning False, so at this point that's a pattern that 
should be consistently supported by the standard library.

Note that a filesystem may allow ":" as name character, such as the VirtualBox 
shared-folder filesystem redirector. But the latter brings up yet another 
twist. Adding a redirector into the device stack, and thus including the MUP 
(multiple UNC provider) device, brings along more path-parsing baggage. In this 
case a component name with ":" in it fails as bad syntax, which gets mapped to 
WinAPI ERROR_BAD_PATHNAME (161), and thus C ENOENT, and ultimately 
FileNotFoundError in Python. This is the case regardless of the filesystem. For 
example, let's use the SMB redirector to set the "//localhost/C$" share for the 
"C:" drive as the working directory:

    >>> os.chdir('//localhost/C$')
    >>> os.stat('http://w.org')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    FileNotFoundError: [WinError 161] The specified path is invalid: 
'http://w.org'

    >>> Path('http://w.org').exists()
    False

---

[1] https://docs.microsoft.com/en-us/windows/win32/fileio/file-streams

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42855>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to