diff options
author | Guido van Rossum <guido@python.org> | 1997-06-02 23:11:57 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-06-02 23:11:57 (GMT) |
commit | 77e1db3b346411c334a36ccd0d2206ff5c71cc90 (patch) | |
tree | 16d893a92bb9e7b3e303f7e8c297ee2271643687 /Lib/ntpath.py | |
parent | dafce6db7bd26e0832359bca10b10525826c0d56 (diff) | |
download | cpython-77e1db3b346411c334a36ccd0d2206ff5c71cc90.zip cpython-77e1db3b346411c334a36ccd0d2206ff5c71cc90.tar.gz cpython-77e1db3b346411c334a36ccd0d2206ff5c71cc90.tar.bz2 |
Support $HOME in expanduser().
(Who'd thought that *anyone* would be interested in writing ~/foo on NT :-)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index a5bdc05..ea855d5 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -23,6 +23,7 @@ def normcase(s): res = res + c return string.lower(res) + # Return wheter a path is absolute. # Trivial in Posix, harder on the Mac or MS-DOS. # 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 '/\\' +# Join two (or more) paths. + def join(a, *p): path = a for b in p: @@ -244,13 +247,16 @@ def expanduser(path): while i < n and path[i] not in '/\\': i = i+1 if i == 1: - try: - drive=os.environ['HOMEDRIVE'] - except KeyError: - drive = '' - if not os.environ.has_key('HOMEPATH'): + if os.environ.has_key('HOME'): + userhome = os.environ['HOME'] + elif not os.environ.has_key('HOMEPATH'): return path - userhome = join(drive, os.environ['HOMEPATH']) + else: + try: + drive=os.environ['HOMEDRIVE'] + except KeyError: + drive = '' + userhome = join(drive, os.environ['HOMEPATH']) else: return path return userhome + path[i:] |