Chromium Code Reviews| Index: build/android/pylib/cmd_helper.py |
| diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py |
| index aba00be735368e9e931e321b14bef1d46ad1fbf3..b99db589d516b1baf1f980eb7a6f0798631c5d82 100644 |
| --- a/build/android/pylib/cmd_helper.py |
| +++ b/build/android/pylib/cmd_helper.py |
| @@ -9,6 +9,7 @@ import os |
| import pipes |
| import select |
| import signal |
| +import string |
| import StringIO |
| import subprocess |
| import time |
| @@ -19,6 +20,27 @@ try: |
| except ImportError: |
| fcntl = None |
| +_SafeShellChars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./') |
| + |
| +quote = pipes.quote |
|
jbudorick
2014/10/17 09:04:52
I don't think I like this. Let callers use pipes.q
|
| + |
| +def dquote(s): |
|
jbudorick
2014/10/17 09:04:53
While I understand that you're mimicking pipes.quo
perezju
2014/10/17 11:17:09
Done.
|
| + """Return an escaped version of the string using double quotes. |
| + |
| + A sibling to pipes.quote that uses double rather than single quotes. |
| + Meant to be used to quote strings which may contain unsafe characters (e.g. |
| + spaces), while retaining some shell features such as variable interpolation. |
| + |
| + The set of characters that retain their special meaning may depend on the |
| + shell implementation. It usually includes: '$', '`', '\', '!', '*', and '@'. |
| + """ |
| + if not s: |
|
jbudorick
2014/10/17 09:04:52
Also, this function should have some unit tests.
perezju
2014/10/17 11:17:09
Done.
|
| + return '""' |
| + if all(c in _SafeShellChars for c in s): |
| + return s |
| + else: |
| + return '"' + s.replace('"', '\\"') + '"' |
| + |
| def Popen(args, stdout=None, stderr=None, shell=None, cwd=None, env=None): |
| return subprocess.Popen( |
| @@ -88,7 +110,7 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False): |
| elif shell: |
| raise Exception('array args must be run with shell=False') |
| else: |
| - args_repr = ' '.join(map(pipes.quote, args)) |
| + args_repr = ' '.join(map(quote, args)) |
| s = '[host]' |
| if cwd: |