def convert_command_args(args):
 assert isinstance(args, list)
 def convert(arg):
  if six.PY2:
   if isinstance(arg, six.text_type):
    arg = arg.encode(arg_encoding())
  elif isinstance(arg, bytes):
   arg = arg.decode(arg_encoding(), 'surrogateescape')
  return arg
 return [convert(a) for a in args]

def convert_command_args ( args ) : assert isinstance ( args , list ) def convert ( arg ) : if six . PY2 : if isinstance ( arg , six . text_type ) : arg = arg . encode ( arg_encoding ( ) ) elif isinstance ( arg , bytes ) : arg = arg . decode ( arg_encoding ( ) , 'surrogateescape' ) return arg return [ convert ( a ) for a in args ]
convert command arguments to bytestrings on python 2 and surrogate-escaped strings on python 3 .