def escape_string(string):
    """Escape a string for use in Gerrit commands.

    :arg str string: The string to escape.

    :returns: The string with necessary escapes and surrounding double quotes
        so that it can be passed to any of the Gerrit commands that require
        double-quoted strings.

    """
    result = string
    result = result.replace('\\', '\\\\')
    result = result.replace('"', '\\"')
    return '"' + result + '"'
Escape a string for use in Gerrit commands.

    :arg str string: The string to escape.

    :returns: The string with necessary escapes and surrounding double quotes
        so that it can be passed to any of the Gerrit commands that require
        double-quoted strings.