summaryrefslogtreecommitdiffstats
path: root/Lib/pipes.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pipes.py')
-rw-r--r--Lib/pipes.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/pipes.py b/Lib/pipes.py
index 6a473ae..51666a8 100644
--- a/Lib/pipes.py
+++ b/Lib/pipes.py
@@ -249,20 +249,18 @@ def makepipeline(infile, steps, outfile):
# Reliably quote a string as a single argument for /bin/sh
-_safechars = string.ascii_letters + string.digits + '!@%_-+=:,./' # Safe unquoted
-_funnychars = '"`$\\' # Unsafe inside "double quotes"
+# Safe unquoted
+_safechars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
def quote(file):
+ """Return a shell-escaped version of the file string."""
for c in file:
if c not in _safechars:
break
else:
+ if not file:
+ return "''"
return file
- if '\'' not in file:
- return '\'' + file + '\''
- res = ''
- for c in file:
- if c in _funnychars:
- c = '\\' + c
- res = res + c
- return '"' + res + '"'
+ # use single quotes, and put single quotes into double quotes
+ # the string $'b is then quoted as '$'"'"'b'
+ return "'" + file.replace("'", "'\"'\"'") + "'"