2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 from driver_log import Log
10 ######################################################################
14 ######################################################################
25 # String was not properly escaped in the first place?
28 # TODO(pdox): Simplify this function by moving more of it into unescape
31 """Split a shell-style string up into a list of distinct arguments.
32 For example: split('cmd -arg1 -arg2="a b c"')
33 Returns ['cmd', '-arg1', '-arg2=a b c']
35 assert(isinstance(s, types.StringTypes))
46 elif s[i] == ' ' and not inquote:
53 Log.Fatal('Unterminated \\ escape sequence')
62 Log.Fatal('Unterminated quote')
69 """Turn a list into a shell-style string For example:
70 shell.join([ 'a', 'b', 'c d e' ]) = 'a b "c d e"'
72 return ' '.join([ shell.escape(a) for a in args ])
76 """Shell-escape special characters in a string
77 Surround with quotes if necessary
79 s = s.replace('\\', '\\\\')
80 s = s.replace('"', '\\"')