diff options
| author | Guido van Rossum <guido@python.org> | 1994-08-01 11:34:53 (GMT) | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1994-08-01 11:34:53 (GMT) | 
| commit | b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af (patch) | |
| tree | 9362939305b2d088b8f19a530c9015d886bc2801 /Lib/posixpath.py | |
| parent | 2979b01ff88ac4c5b316d9bf98edbaaaffac8e24 (diff) | |
| download | cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.zip cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.gz cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.bz2  | |
Merge alpha100 branch back to main trunk
Diffstat (limited to 'Lib/posixpath.py')
| -rw-r--r-- | Lib/posixpath.py | 48 | 
1 files changed, 27 insertions, 21 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 96116d1..6110f8e 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -130,7 +130,7 @@ def isdir(path):  # Is a path a regular file? -# This follows symbolic links, so both islink() and isdir() can be true +# This follows symbolic links, so both islink() and isfile() can be true  # for the same path.  def isfile(path): @@ -205,7 +205,7 @@ def walk(top, func, arg):  	for name in names:  		if name not in exceptions:  			name = join(top, name) -			if isdir(name): +			if isdir(name) and not islink(name):  				walk(name, func, arg) @@ -239,29 +239,35 @@ def expanduser(path):  # Expand paths containing shell variable substitutions. -# This is done by piping it through the shell. -# Shell quoting characters (\ " ' `) are protected by a backslash. -# NB: a future version may avoid starting a subprocess and do the -# substitutions internally.  This may slightly change the syntax -# for variables. +# This expands the forms $variable and ${variable} only. +# Non-existant variables are left unchanged. + +_varprog = None  def expandvars(path): +	global _varprog  	if '$' not in path:  		return path -	q = '' -	for c in path: -		if c in ('\\', '"', '\'', '`'): -			c = '\\' + c -		q = q + c -	d = '!' -	if q == d: -		d = '+' -	p = posix.popen('cat <<' + d + '\n' + q + '\n' + d + '\n', 'r') -	res = p.read() -	del p -	if res[-1:] == '\n': -		res = res[:-1] -	return res +	if not _varprog: +		import regex +		_varprog = regex.compile('$\([a-zA-Z0-9_]+\|{[^}]*}\)') +	i = 0 +	while 1: +		i = _varprog.search(path, i) +		if i < 0: +			break +		name = _varprog.group(1) +		j = i + len(_varprog.group(0)) +		if name[:1] == '{' and name[-1:] == '}': +			name = name[1:-1] +		if posix.environ.has_key(name): +			tail = path[j:] +			path = path[:i] + posix.environ[name] +			i = len(path) +			path = path + tail +		else: +			i = j +	return path  # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.  | 
