python: LRU cache for the dot->svg conversion
* wrap/python/spot.py: Here.
This commit is contained in:
parent
31b3862f48
commit
54a8ce502d
1 changed files with 11 additions and 2 deletions
|
|
@ -20,17 +20,26 @@
|
||||||
from spot_impl import *
|
from spot_impl import *
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
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()
|
_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.
|
||||||
|
@lru_cache(maxsize=64)
|
||||||
|
def _str_to_svg(str):
|
||||||
dotty = subprocess.Popen(['dot', '-Tsvg'],
|
dotty = subprocess.Popen(['dot', '-Tsvg'],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
dotty.stdin.write(ostr.str().encode('utf-8'))
|
dotty.stdin.write(str)
|
||||||
res = dotty.communicate()
|
res = dotty.communicate()
|
||||||
return res[0].decode('utf-8')
|
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):
|
def _render_automaton_as_svg(a, opt=None):
|
||||||
ostr = ostringstream()
|
ostr = ostringstream()
|
||||||
dotty_reachable(ostr, a, opt)
|
dotty_reachable(ostr, a, opt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue