mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Support $HOME in expanduser().
(Who'd thought that *anyone* would be interested in writing ~/foo on NT :-)
This commit is contained in:
parent
dafce6db7b
commit
77e1db3b34
1 changed files with 12 additions and 6 deletions
|
|
@ -23,6 +23,7 @@ def normcase(s):
|
||||||
res = res + c
|
res = res + c
|
||||||
return string.lower(res)
|
return string.lower(res)
|
||||||
|
|
||||||
|
|
||||||
# Return wheter a path is absolute.
|
# Return wheter a path is absolute.
|
||||||
# Trivial in Posix, harder on the Mac or MS-DOS.
|
# Trivial in Posix, harder on the Mac or MS-DOS.
|
||||||
# For DOS it is absolute if it starts with a slash or backslash (current
|
# For DOS it is absolute if it starts with a slash or backslash (current
|
||||||
|
|
@ -34,6 +35,8 @@ def isabs(s):
|
||||||
return s != '' and s[:1] in '/\\'
|
return s != '' and s[:1] in '/\\'
|
||||||
|
|
||||||
|
|
||||||
|
# Join two (or more) paths.
|
||||||
|
|
||||||
def join(a, *p):
|
def join(a, *p):
|
||||||
path = a
|
path = a
|
||||||
for b in p:
|
for b in p:
|
||||||
|
|
@ -244,13 +247,16 @@ def expanduser(path):
|
||||||
while i < n and path[i] not in '/\\':
|
while i < n and path[i] not in '/\\':
|
||||||
i = i+1
|
i = i+1
|
||||||
if i == 1:
|
if i == 1:
|
||||||
try:
|
if os.environ.has_key('HOME'):
|
||||||
drive=os.environ['HOMEDRIVE']
|
userhome = os.environ['HOME']
|
||||||
except KeyError:
|
elif not os.environ.has_key('HOMEPATH'):
|
||||||
drive = ''
|
|
||||||
if not os.environ.has_key('HOMEPATH'):
|
|
||||||
return path
|
return path
|
||||||
userhome = join(drive, os.environ['HOMEPATH'])
|
else:
|
||||||
|
try:
|
||||||
|
drive=os.environ['HOMEDRIVE']
|
||||||
|
except KeyError:
|
||||||
|
drive = ''
|
||||||
|
userhome = join(drive, os.environ['HOMEPATH'])
|
||||||
else:
|
else:
|
||||||
return path
|
return path
|
||||||
return userhome + path[i:]
|
return userhome + path[i:]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue