summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-09 13:54:50 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-09 13:54:50 (GMT)
commit4732ccf6425b155cf7b2eb22c2dd071b97a462ff (patch)
tree77d1872d68bf4415a88c1424e854c2761413ccbf /Lib/posixpath.py
parent21803b8a6f9e78fc220bf95658182f7ca3265173 (diff)
downloadcpython-4732ccf6425b155cf7b2eb22c2dd071b97a462ff.zip
cpython-4732ccf6425b155cf7b2eb22c2dd071b97a462ff.tar.gz
cpython-4732ccf6425b155cf7b2eb22c2dd071b97a462ff.tar.bz2
Added emacs.py (for misc/py-connect.el).
posixpath.py: added undocumented expanndvars() (expands $VAR in string).
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index b178e67..d2bda10 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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