summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py48
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.