Make all python code compatible with Python 2.x and Python 3.x.
* wrap/python/buddy.i (__le__, __lt__, __eq__, __ne__, __ge__ __gt__): New operators for bdd. * wrap/python/spot.i (__le__, __lt__, __eq__, __ne__, __ge__ __gt__, __hash__): New operators for formula. (nl_cout, nl_cerr): New functions. * wrap/python/tests/bddnqueen.py, wrap/python/tests/interdep.py, wrap/python/tests/ltl2tgba.py, wrap/python/tests/ltlparse.py, wrap/python/tests/ltlsimple.py, wrap/python/tests/minato.py, wrap/python/tests/modgray.py: Adjust to the new print syntax by using sys.output.write() or nl_cout() instead. * wrap/python/tests/optionmap.py: Remove all print calls. * wrap/python/ajax/spot.in: Massive adjustments in order to work with both Python 2 and 3. In python 3, reopening stdout as unbuffered requires it to be open as binary, which in turns requires any string output to be encoded manually. BaseHTTPServer and CGIHTTPServer have been merged into http.server, so we have to try two different import syntaxes. execfile no longer exists, so it has to be emulated. This also fixes two bugs where the script would segfault on empty input, or when calling Tau03 on automata with less then one acceptance conditions.
This commit is contained in:
parent
5e77b2498a
commit
61127a3fd5
12 changed files with 262 additions and 155 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2011 Laboratoire de Recherche et Développement
|
||||
# de l'EPITA.
|
||||
# Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et
|
||||
# Développement de l'EPITA.
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6
|
||||
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
|
||||
# Pierre et Marie Curie.
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
import sys
|
||||
from buddy import *
|
||||
from spot import nl_cout
|
||||
|
||||
# Build the requirements for all other fields than (i,j) assuming
|
||||
# that (i,j) has a queen.
|
||||
|
|
@ -89,15 +90,15 @@ for i in side:
|
|||
# Build requirements for each variable(field).
|
||||
for i in side:
|
||||
for j in side:
|
||||
print "Adding position %d, %d" % (i, j)
|
||||
sys.stdout.write("Adding position %d, %d\n" % (i, j))
|
||||
build(i, j)
|
||||
|
||||
# Print the results.
|
||||
print "There are", bdd_satcount(queen), "solutions"
|
||||
print "one is:"
|
||||
sys.stdout.write("There are %d solutions, one is:\n" %
|
||||
bdd_satcount(queen))
|
||||
solution = bdd_satone(queen)
|
||||
bdd_printset(solution)
|
||||
print
|
||||
nl_cout()
|
||||
|
||||
# Cleanup all BDD variables before calling bdd_done(), otherwise
|
||||
# bdd_delref will be called after bdd_done() and this is unsafe in
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2003, 2004, 2010 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'EPITA.
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6
|
||||
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
|
||||
# Pierre et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
#
|
||||
|
|
@ -24,6 +26,7 @@
|
|||
# are not problematic.
|
||||
import buddy
|
||||
import spot
|
||||
import sys
|
||||
e = spot.default_environment.instance()
|
||||
p = spot.empty_parse_error_list()
|
||||
f = spot.parse('GFa', p, e)
|
||||
|
|
@ -31,13 +34,13 @@ dict = spot.bdd_dict()
|
|||
a = spot.ltl_to_tgba_lacim(f, dict)
|
||||
s0 = a.get_init_state()
|
||||
b = s0.as_bdd()
|
||||
print b
|
||||
sys.stdout.write("%s\n" % b)
|
||||
iter = a.succ_iter(s0)
|
||||
iter.first()
|
||||
while not iter.done():
|
||||
c = iter.current_condition()
|
||||
print c
|
||||
sys.stdout.write("%s\n" % c)
|
||||
b &= c # `&=' is defined only in buddy. So if this statement works
|
||||
# it means buddy can grok spot's objects.
|
||||
iter.next()
|
||||
print b
|
||||
sys.stdout.write("%s\n" % b)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
|
||||
# de l'Epita (LRDE).
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2009, 2010, 2012 Laboratoire de Recherche et
|
||||
# Développement de l'Epita (LRDE).
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -30,7 +30,7 @@ import getopt
|
|||
import spot
|
||||
|
||||
def usage(prog):
|
||||
print "Usage: ", prog, """ [OPTIONS...] formula
|
||||
sys.stderr.write("""Usage: %s [OPTIONS...] formula
|
||||
|
||||
Options:
|
||||
-a display the acceptance_conditions BDD, not the reachability graph
|
||||
|
|
@ -41,7 +41,8 @@ Options:
|
|||
-r display the relation BDD, not the reachability graph
|
||||
-R same as -r, but as a set
|
||||
-t display reachable states in LBTT's format
|
||||
-v display the BDD variables used by the automaton"""
|
||||
-v display the BDD variables used by the automaton
|
||||
""" % prog)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
|
|
@ -122,12 +123,12 @@ if f:
|
|||
if concrete:
|
||||
spot.bdd_print_set(cout, concrete.get_dict(),
|
||||
concrete.get_core_data().relation)
|
||||
print
|
||||
spot.nl_cout()
|
||||
elif output == 4:
|
||||
if concrete:
|
||||
spot.bdd_print_set(cout, concrete.get_dict(),
|
||||
concrete.get_core_data().acceptance_conditions)
|
||||
print
|
||||
spot.nl_cout()
|
||||
elif output == 5:
|
||||
a.get_dict().dump(cout)
|
||||
elif output == 6:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2009, 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'Epita (LRDE).
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -36,12 +36,12 @@ for str1 in l:
|
|||
sys.exit(1)
|
||||
str2 = str(f)
|
||||
f.destroy()
|
||||
print str2
|
||||
sys.stdout.write(str2 + "\n")
|
||||
# Try to reparse the stringified formula
|
||||
f = spot.parse(str2, p, e)
|
||||
if spot.format_parse_errors(spot.get_cout(), str2, p):
|
||||
sys.exit(1)
|
||||
print f
|
||||
sys.stdout.write(str(f) + "\n")
|
||||
f.destroy()
|
||||
|
||||
assert spot.atomic_prop.instance_count() == 0
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2009, 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'Epita (LRDE).
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
# 02111-1307, USA.
|
||||
|
||||
import spot
|
||||
import sys
|
||||
|
||||
e = spot.default_environment.instance()
|
||||
|
||||
|
|
@ -42,18 +43,18 @@ op2 = spot.multop.instance(spot.multop.And, op, c)
|
|||
# suppressed, so we don't attempt to reuse it elsewhere.
|
||||
del op, c
|
||||
|
||||
print 'op2 =', op2
|
||||
sys.stdout.write('op2 = %s\n' % str(op2))
|
||||
|
||||
op3 = spot.multop.instance(spot.multop.And, b,
|
||||
spot.multop.instance(spot.multop.And, c2, a))
|
||||
spot.multop.instance(spot.multop.And, c2, a))
|
||||
del a, b, c2
|
||||
|
||||
print 'op3 =', op3
|
||||
sys.stdout.write('op3 = %s\n' % str(op3))
|
||||
assert op2 == op3
|
||||
|
||||
op4 = spot.multop.instance(spot.multop.Or, op2, op3)
|
||||
|
||||
print 'op4 =', op4
|
||||
sys.stdout.write('op4 = %s\n' % str(op4))
|
||||
assert op4 == op2
|
||||
|
||||
del op2, op3
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2004, 2010 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'Epita
|
||||
# Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -40,7 +42,7 @@ i = isop.next()
|
|||
l = []
|
||||
while i != buddy.bddfalse:
|
||||
buddy.bdd_printset(i)
|
||||
print
|
||||
spot.nl_cout()
|
||||
l.append(i)
|
||||
i = isop.next()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2004, 2010 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'Epita.
|
||||
# Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -21,6 +23,7 @@
|
|||
# 02111-1307, USA.
|
||||
|
||||
import spot
|
||||
import sys
|
||||
|
||||
class test(spot.loopless_modular_mixed_radix_gray_code):
|
||||
def __init__(self, lim):
|
||||
|
|
@ -43,7 +46,7 @@ class test(spot.loopless_modular_mixed_radix_gray_code):
|
|||
while not self.done():
|
||||
m = "".join(self.msg)
|
||||
res.append(m)
|
||||
print m
|
||||
sys.stdout.write(m + "\n")
|
||||
self.next()
|
||||
return res
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# -*- mode: python; coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2005, 2010 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement
|
||||
# de l'EPITA.
|
||||
# Copyright (C) 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -47,17 +49,13 @@ assert o.get('optB') == 0
|
|||
assert o.get('optC') == 1
|
||||
|
||||
res = o.parse_options("!")
|
||||
print res
|
||||
assert res == "!"
|
||||
|
||||
res = o.parse_options("foo, !opt = 1")
|
||||
print res
|
||||
assert res == "!opt = 1"
|
||||
|
||||
res = o.parse_options("foo=3, opt == 1")
|
||||
print res
|
||||
assert res == "opt == 1"
|
||||
|
||||
res = o.parse_options("foo=3opt == 1")
|
||||
print res
|
||||
assert res == "3opt == 1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue