This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients domdfcoding2, eryksun, gaborjbernat, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-01-07.13:04:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610024678.14.0.597474308116.issue42855@roundup.psfhosted.org>
In-reply-to
Content
> "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
History
Date User Action Args
2021-01-07 13:04:38eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, gaborjbernat, domdfcoding2
2021-01-07 13:04:38eryksunsetmessageid: <1610024678.14.0.597474308116.issue42855@roundup.psfhosted.org>
2021-01-07 13:04:38eryksunlinkissue42855 messages
2021-01-07 13:04:37eryksuncreate