Commit 54a8ce50 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

python: LRU cache for the dot->svg conversion

* wrap/python/ Here.
parent 31b3862f
......@@ -20,17 +20,26 @@
from spot_impl import *
import subprocess
import sys
from functools import lru_cache
# Global BDD dict so that we do not have to create one in user code.
_bdd_dict = make_bdd_dict()
def _ostream_to_svg(ostr):
# Add a small LRU cache so that when we display automata into a
# interactive widget, we avoid some repeated calls to dot for
# identical inputs.
def _str_to_svg(str):
dotty = subprocess.Popen(['dot', '-Tsvg'],
res = dotty.communicate()
return res[0].decode('utf-8')
def _ostream_to_svg(ostr):
return _str_to_svg(ostr.str().encode('utf-8'))
def _render_automaton_as_svg(a, opt=None):
ostr = ostringstream()
dotty_reachable(ostr, a, opt)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment