mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Added emacs.py (for misc/py-connect.el).
posixpath.py: added undocumented expanndvars() (expands $VAR in string).
This commit is contained in:
parent
21803b8a6f
commit
4732ccf642
2 changed files with 44 additions and 0 deletions
|
@ -230,3 +230,29 @@ def expanduser(path):
|
|||
return path
|
||||
userhome = pwent[5]
|
||||
return userhome + path[i:]
|
||||
|
||||
|
||||
# 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.
|
||||
|
||||
def expandvars(path):
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue