diff options
| author | Guido van Rossum <guido@python.org> | 1995-08-10 19:34:50 (GMT) | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1995-08-10 19:34:50 (GMT) | 
| commit | 99bf06b2fc7b2636edb46994fa1a9f12eda6b051 (patch) | |
| tree | 94c7bafd4eb23417ddaaeeb919497c02868e68c4 /Lib/ntpath.py | |
| parent | 92794e30cb9ef26f0d0df539d5df9723b8d5baa8 (diff) | |
| download | cpython-99bf06b2fc7b2636edb46994fa1a9f12eda6b051.zip cpython-99bf06b2fc7b2636edb46994fa1a9f12eda6b051.tar.gz cpython-99bf06b2fc7b2636edb46994fa1a9f12eda6b051.tar.bz2  | |
same thing as for dospath, plus HOMEDRIVE/HOMEPATH support
Diffstat (limited to 'Lib/ntpath.py')
| -rw-r--r-- | Lib/ntpath.py | 23 | 
1 files changed, 11 insertions, 12 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 1479e1b..1109d44 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -1,4 +1,4 @@ -# Module 'dospath' -- common operations on DOS pathnames +# Module 'ntpath' -- common operations on DOS pathnames  import os  import stat @@ -7,27 +7,22 @@ import string  # Normalize the case of a pathname.  # On MS-DOS it maps the pathname to lowercase, turns slashes into -# backslashes and maps invalid consecutive characters to a single '_'. +# backslashes.  # Other normalizations (such as optimizing '../' away) are not allowed  # (this is done by normpath). - -mapchar = '_' +# Previously, this version mapped invalid consecutive characters to a  +# single '_', but this has been removed.  This functionality should  +# possibly be added as a new function.  def normcase(s):  	res, s = splitdrive(s)  	for c in s:  		if c in '/\\':  			res = res + os.sep -		elif c == '.' and res[-1:] == os.sep: -			res = res + mapchar + c -		elif ord(c) < 32 or c in ' "*+,:;<=>?[]|': -			if res[-1:] != mapchar: -				res = res + mapchar  		else:  			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 @@ -243,9 +238,13 @@ def expanduser(path):  	while i < n and path[i] not in '/\\':  		i = i+1  	if i == 1: -		if not os.environ.has_key('HOME'): +		try: +			drive=os.environ['HOMEDRIVE'] +		except KeyError: +			drive = '' +		if not os.environ.has_key('HOMEPATH'):  			return path -		userhome = os.environ['HOME'] +		userhome = join(drive, os.environ['HOMEPATH'])  	else:  		return path  	return userhome + path[i:]  | 
