def write_dot(g):
    """Replacement for pygraph.readwrite.dot.write, which is dog slow.

    Note:
        This isn't a general replacement. It will work for the graphs that
        Rez generates, but there are no guarantees beyond that.

    Args:
        g (`pygraph.digraph`): Input graph.

    Returns:
        str: Graph in dot format.
    """
    lines = ["digraph g {"]

    def attrs_txt(items):
        if items:
            txt = ", ".join(('%s="%s"' % (k, str(v).strip('"')))
                            for k, v in items)
            return '[' + txt + ']'
        else:
            return ''

    for node in g.nodes():
        atxt = attrs_txt(g.node_attributes(node))
        txt = "%s %s;" % (node, atxt)
        lines.append(txt)

    for e in g.edges():
        edge_from, edge_to = e
        attrs = g.edge_attributes(e)

        label = str(g.edge_label(e))
        if label:
            attrs.append(("label", label))

        atxt = attrs_txt(attrs)
        txt = "%s -> %s %s;" % (edge_from, edge_to, atxt)
        lines.append(txt)

    lines.append("}")
    return '\n'.join(lines)