Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77e1db3

Browse files
committed
Support $HOME in expanduser().
(Who'd thought that *anyone* would be interested in writing ~/foo on NT :-)
1 parent dafce6d commit 77e1db3

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

Lib/ntpath.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def normcase(s):
2323
res = res + c
2424
return string.lower(res)
2525

26+
2627
# Return wheter a path is absolute.
2728
# Trivial in Posix, harder on the Mac or MS-DOS.
2829
# For DOS it is absolute if it starts with a slash or backslash (current
@@ -34,6 +35,8 @@ def isabs(s):
3435
return s != '' and s[:1] in '/\\'
3536

3637

38+
# Join two (or more) paths.
39+
3740
def join(a, *p):
3841
path = a
3942
for b in p:
@@ -244,13 +247,16 @@ def expanduser(path):
244247
while i < n and path[i] not in '/\\':
245248
i = i+1
246249
if i == 1:
247-
try:
248-
drive=os.environ['HOMEDRIVE']
249-
except KeyError:
250-
drive = ''
251-
if not os.environ.has_key('HOMEPATH'):
250+
if os.environ.has_key('HOME'):
251+
userhome = os.environ['HOME']
252+
elif not os.environ.has_key('HOMEPATH'):
252253
return path
253-
userhome = join(drive, os.environ['HOMEPATH'])
254+
else:
255+
try:
256+
drive=os.environ['HOMEDRIVE']
257+
except KeyError:
258+
drive = ''
259+
userhome = join(drive, os.environ['HOMEPATH'])
254260
else:
255261
return path
256262
return userhome + path[i:]

0 commit comments

Comments
 (0)