def quote_if_necessary(s):
    """Enclose attribute value in quotes, if needed."""
    if isinstance(s, bool):
        if s is True:
            return "True"
        return "False"

    if s is None:
        return f"{s}"

    if not isinstance(s, str):
        return s

    if not s:
        return s

    if needs_quotes(s):
        replace = {
            '"': r"\"",
            "\n": r"\n",
            "\r": r"\r",
        }
        for a, b in replace.items():
            s = s.replace(a, b)

        return '"' + s + '"'

    return s
Enclose attribute value in quotes, if needed.
python/aitemplate/utils/visualization/pydot.py