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.

classification
Title: Suggested change in how ntpath.expanduser works
Type: Stage:
Components: Windows Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: loewis, timehorse
Priority: normal Keywords: patch

Created on 2003-09-07 22:08 by timehorse, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ntpath.py timehorse, 2003-09-07 22:08 ntpath.py with proposed changes
Messages (3)
msg44581 - (view) Author: Jeffrey C. Jacobs (timehorse) Date: 2003-09-07 22:08
There exists a problem in the MS Knowledge base 
(http://support.microsoft.com/?kbid=236813) which 
documents some issues with using the %HOMEDRIVE% 
and %HOMEPATH% to generate a home directory.  
(Note, in XP systems these variables seeom to set 
correctly, though this problem exists in Win2k and likely 
WinNT.)  Given this and that in non-network situations 
these variables are not preferred I propose the changes 
explained in the following note:

Windows may be run over a network (Distributed File 
System or DFS) or as a stand-alone [multi-user] box.  In 
order to determine a tilde-expanded network path in a 
DFS environment, one must use the concatenation of %
HOMEDRIVE% and %HOMEPATH%.  In the stand-alone 
case, home directories are not part of a DFS path 
expansion.  On these machines, %HOMEDRIVE% and %
HOMEPATH% may default to "C:" [%SYSTEMDRIVE% ??] 
and "\", respectively.  While a %HOMEPATH% of "\" is 
quite common under DFS as well, if the "network" path 
is "C:" [or %SYSTEMDRIVE%], this is a stand-alone 
system and stand-alone rules should apply by default.  If 
however the %USERPROFILE% variable does not exist, 
the DFS interpretation will default and you still end up 
with "C:\" as your result.

The upshot of a stand-alone system is that other users 
can be tilde-expanded based on the variable %
ALLUSERSPROFILE%/../<name>, where name is the name 
given in the tilde.  However, since Windows allows 
whitespace names, the tilde must either be 8.3 
contracted or the fully-qualified user name.  This 
function will not verify if the name exits -- that is left to 
the caller's use of the result.  We require %
ALLUSERSPROFILE% rather than just manipulating %
USERPROFILE% to assure this is a multi-user system.

Finally, the local_path variable indicates whether 
the "My Documents" element should be appended.  On 
Win9x boxes which don't have a DFS path or %
USERPROFILE%, this translates typically to "C:\My 
Documents".  For NT, Win2k and XP, this typically 
means "%USERPROFILE%/My Documents".  This is 
because the profile is not a good directory to edit files 
in -- it is the equivalent to writing to a hidden system 
directory under UNIX.

Note however that we still prefer %HOME% because it 
was almost certainly manually set and this is not "My 
Documents" expanded.

A similar implementation can be provided in the 
dospath.expanduser method though here the "My 
Documents" expansion should only be used on Win9x 
machines, not true DOS systems.  Since the ntpath 
library SHOULD be imported on these Win9x systems 
(AFAICT from the Documentation) no change would 
therefore be necessary in dospath to support this.
msg44582 - (view) Author: Jeffrey C. Jacobs (timehorse) Date: 2003-09-08 11:36
Logged In: YES 
user_id=836867

I forgot to mention this solution unfortunately would only 
work on English windows systems, as international Windows 
use the literal translation of "My Documents", e.g. "Mes 
Documents" for the official user folder.  I will look into how I 
might fix this problem in the generic case (perhaps by 
scanning the registry) but would also like to add perhaps 
given that Mac OS X has gone in this direction that there be 
a generic get_my_documents([user]), get_my_pictures
([user]) and get_my_desktop([user]) supported as stubs in 
those systems that don't support it and return the relavent 
directory for nt and OSX.
msg44583 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-08-18 12:48
Logged In: YES 
user_id=21627

It appears that no update to this patch has been received -
considering it withdrawn.
History
Date User Action Args
2022-04-10 16:11:03adminsetgithub: 39198
2003-09-07 22:08:10timehorsecreate