[ python-Bugs-796219 ] ntpath.expanduser() is still wrong
SourceForge.net
noreply at sourceforge.net
Sat Mar 20 17:49:02 EST 2004
Bugs item #796219, was opened at 2003-08-27 16:11
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=796219&group_id=5470
Category: Windows
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: ntpath.expanduser() is still wrong
Initial Comment:
I found a system with the following setup:
- os.getenv("HOME") returns "%USERPROFILE%"
- os.getenv("USERPROFILE") returns the home directory
Currently, ntpath.py doesn't expand ~ correctly in this
case.
The fix is pretty simple, I'll try to submit it if I
have time.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2004-03-20 17:49
Message:
Logged In: YES
user_id=6380
Unclear what I'm asked to do here. Josiah, could you produce
an actual patch against CVS rather than random example code?
If you have forward slashes, you should use
os.path.normpath(). Why doesn't that work?
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2003-09-30 10:00
Message:
Logged In: YES
user_id=31435
Assigned back to Guido.
----------------------------------------------------------------------
Comment By: Josiah Carlson (josiahcarlson)
Date: 2003-09-30 02:33
Message:
Logged In: YES
user_id=341410
I just noticed that I've got some forward slashes in various
paths on my windows machines...here's some updated code:
def expandfull(var, rem=3):
if not rem:
return os.path.expandvars(var)
a = os.path.expandvars(var)
b = []
d = [b.extend(i.split('\')) for i in a.split('/')]
c = []
for i in b:
if '%' in i:
c.append(expandfull(i), rem-1)
else:
c.append(i)
return '\'.join(c)
----------------------------------------------------------------------
Comment By: Christos Georgiou (tzot)
Date: 2003-08-30 05:55
Message:
Logged In: YES
user_id=539787
I stand corrected; multiple backslashes inside a path are not
merged into one on Windows. Thank you.
----------------------------------------------------------------------
Comment By: Josiah Carlson (josiahcarlson)
Date: 2003-08-29 14:48
Message:
Logged In: YES
user_id=341410
Sourceforge ate my double-backslashes.
All '\' should be '\\'.
----------------------------------------------------------------------
Comment By: Josiah Carlson (josiahcarlson)
Date: 2003-08-29 14:20
Message:
Logged In: YES
user_id=341410
The code you offered won't work correctly for all
environment variable returns. An example that would kill
your code:
%SYSTEMROOT%\System32
def expandfull(var, rem=3):
if not rem:
return expandvars(var)
a = expandvars(var)
b = a.split('\')
c = []
for i in b:
if '%' in i:
c.append(expandfull(i), rem-1)
else:
c.append(i)
return '\'.join(c)
The above would work properly for all environment variables.
----------------------------------------------------------------------
Comment By: Christos Georgiou (tzot)
Date: 2003-08-29 04:38
Message:
Logged In: YES
user_id=539787
If expandvars worked for nt variable syntax too, then just
before the expanduser final return, the following code would
suffice, right?
max_recursion = 3
while '%' in userhome and max_recursion > 0:
userhome = expandvars(userhome)
max_recursion -= 1
ignoring the fact that path[1:] could contain variables too.
Shouldn't expandvars be made to work with %var% format
too? If yes, I'll offer code.
----------------------------------------------------------------------
Comment By: Jarek Zgoda (zgoda)
Date: 2003-08-28 03:47
Message:
Logged In: YES
user_id=92222
This is very common setting on Windows2000 Professional.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=796219&group_id=5470
More information about the Python-bugs-list
mailing list