mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merge alpha100 branch back to main trunk
This commit is contained in:
parent
2979b01ff8
commit
b6775db241
176 changed files with 5302 additions and 3668 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue