Eryk Sun <[email protected]> added the comment:
> I'm not sure if "}" could ever be valid drive letter
The Windows file API is designed in a way to support almost any Unicode BMP
character in a DOS drive designation. For example, the following creates "{:"
as a substitute drive for "C:\\Temp":
>>> DefineDosDevice(0, '{:', 'C:\\Temp')
Drive "{:" has a working directory:
>>> os.mkdir('{:/Eggs')
>>> os.chdir('{:/Eggs')
>>> os.chdir('C:/')
>>> ntpath.abspath('{:')
'{:\\Eggs'
The latter is based on a hidden environment variable named "={:", which WinAPI
GetFullPathNameW consumes:
>>> GetEnvironmentVariable('={:')
'{:\\Eggs'
That said, only drive letters A-Z count for WinAPI GetLogicalDrives and
GetLogicalDriveStrings, and these are the only drive names that can be assigned
normally. So it's not important to handle "{:" as a drive. Whatever makes the
code simpler.
> ":" can definitely be used in filenames.
Colon is allowed in filepaths, such as in device names and stream designations,
but most filesystems do not allow colon in filenames. Exceptions include the
named-pipe filesystem and some redirectors for non-native filesystems, such as
the VirtualBox shared-folder filesystem.
The Windows API reserves colon as the delimiter for file streams [1]. In stream
designations such as "filename:streamname:streamtype", the colon is not part of
the filename, stream name, or stream type name.
"{:3" could be a file named "{" with a data stream named "3". (The "DATA$"
stream type is implicit.) The workaround for accessing a named stream in a file
with a single-character filename is to use an explicitly relative path such as
"./{:3". This works fine with ntpath.join:
>>> ntpath.join('3', './{:3')
'3\\./{:3'
>>> ntpath.normpath(ntpath.join('3', './{:3'))
'3\\{:3'
---
[1] https://docs.microsoft.com/en-us/windows/win32/fileio/file-streams
----------
nosy: +eryksun
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41565>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com