def convert_command_args(args):
    """Convert command arguments to bytestrings on Python 2 and
    surrogate-escaped strings on Python 3."""
    assert isinstance(args, list)

    def convert(arg):
        if isinstance(arg, bytes):
            arg = arg.decode(arg_encoding(), 'surrogateescape')
        return arg

    return [convert(a) for a in args]