def list2cmdline(seq):
 result = []
 needquote = False
 for arg in seq:
  bs_buf = []
  if result:
   result.append(' ')
  needquote = ((' ' in arg) or (' DCTB ' in arg) or ('|' in arg) or (not arg))
  if needquote:
   result.append('"')
  for c in arg:
   if (c == '\\'):
    bs_buf.append(c)
   elif (c == '"'):
    result.append((('\\' * len(bs_buf)) * 2))
    bs_buf = []
    result.append('\\"')
   else:
    if bs_buf:
     result.extend(bs_buf)
     bs_buf = []
    result.append(c)
  if bs_buf:
   result.extend(bs_buf)
  if needquote:
   result.extend(bs_buf)
   result.append('"')
 return ''.join(result)

def list2cmdline ( seq ) : result = [ ] needquote = False for arg in seq : bs_buf = [ ] if result : result . append ( ' ' ) needquote = ( ( ' ' in arg ) or ( ' DCTB ' in arg ) or ( '|' in arg ) or ( not arg ) ) if needquote : result . append ( '"' ) for c in arg : if ( c == '\\' ) : bs_buf . append ( c ) elif ( c == '"' ) : result . append ( ( ( '\\' * len ( bs_buf ) ) * 2 ) ) bs_buf = [ ] result . append ( '\\"' ) else : if bs_buf : result . extend ( bs_buf ) bs_buf = [ ] result . append ( c ) if bs_buf : result . extend ( bs_buf ) if needquote : result . extend ( bs_buf ) result . append ( '"' ) return '' . join ( result )
convert list to a cmd .