Conversion to python3, using 2to3.
This commit is contained in:
@@ -19,7 +19,7 @@ def scanThis(fn,f,rewritelist,cnt):
|
||||
mapping.append((lhs,rhs))
|
||||
|
||||
fp = open(fn,"r")
|
||||
for rl in fp.xreadlines():
|
||||
for rl in fp:
|
||||
l = rl
|
||||
if f != None:
|
||||
l = f(l)
|
||||
@@ -34,7 +34,7 @@ def convertEm(f=None,path=".",rewritelist=[],newdir=".",oldext="",newext=None):
|
||||
cnt = 1
|
||||
for fn in fl:
|
||||
ffn = os.path.join(path,fn)
|
||||
print "Processing",ffn
|
||||
print("Processing",ffn)
|
||||
s = scanThis(ffn,f,rewritelist,cnt)
|
||||
if newext == None:
|
||||
fn2 = fn
|
||||
@@ -44,7 +44,7 @@ def convertEm(f=None,path=".",rewritelist=[],newdir=".",oldext="",newext=None):
|
||||
fp = open(ffn2,"w")
|
||||
fp.write(s)
|
||||
fp.close()
|
||||
print "Produced",ffn2
|
||||
print("Produced",ffn2)
|
||||
cnt = cnt+1
|
||||
|
||||
def preprocess(s):
|
||||
@@ -55,7 +55,7 @@ def preprocess(s):
|
||||
|
||||
def main():
|
||||
convertEm(f=preprocess,rewritelist=["@OracleA","@executability","@OracleB"],path=".",newdir="mpa",oldext=".spdl")
|
||||
print "Done."
|
||||
print("Done.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -34,8 +34,8 @@ def stripRowEnd(l):
|
||||
# Assume ends with \\, split by dtl
|
||||
endstr = "\\\\"
|
||||
if not l.endswith(endstr):
|
||||
print "Error: some line does not end with \\\\"
|
||||
print ">>%s<<" % (l)
|
||||
print("Error: some line does not end with \\\\")
|
||||
print(">>%s<<" % (l))
|
||||
sys.exit(-1)
|
||||
|
||||
return l[:-len(endstr)]
|
||||
@@ -63,7 +63,7 @@ def scanAttackFile(fn):
|
||||
prot = None
|
||||
role = None
|
||||
claim = None
|
||||
for rawline in fp.xreadlines():
|
||||
for rawline in fp:
|
||||
|
||||
l = rawline.strip()
|
||||
|
||||
@@ -94,7 +94,7 @@ def scanAttackFile(fn):
|
||||
attl[i] = x[1:-1]
|
||||
|
||||
ak = (prot,role,claim)
|
||||
if ak not in attackmap.keys():
|
||||
if ak not in list(attackmap.keys()):
|
||||
attackmap[ak] = set()
|
||||
attackmap[ak].add(tuple(attl))
|
||||
|
||||
@@ -136,7 +136,7 @@ def mpaTable(attackmap):
|
||||
s += "\\begin{longtable}{|l|lll|l|}\n"
|
||||
s += "\\hline\n"
|
||||
for kk in sorted(ALLCLAIMS):
|
||||
if kk not in attackmap.keys():
|
||||
if kk not in list(attackmap.keys()):
|
||||
continue
|
||||
(prot,role,claim) = kk
|
||||
|
||||
@@ -174,7 +174,7 @@ def mpaTable2(attackmap,tabtype="tabular",options=""):
|
||||
|
||||
# To find the number of columns, we first need to find all protocols involved in two-protocol attacks
|
||||
involved = set()
|
||||
for kk in attackmap.keys():
|
||||
for kk in list(attackmap.keys()):
|
||||
for atl in attackmap[kk]:
|
||||
# convert tuple back to list
|
||||
att = list(atl)
|
||||
@@ -210,7 +210,7 @@ def mpaTable2(attackmap,tabtype="tabular",options=""):
|
||||
s += "\\hline\n"
|
||||
last = None
|
||||
for kk in sorted(ALLCLAIMS):
|
||||
if kk not in attackmap.keys():
|
||||
if kk not in list(attackmap.keys()):
|
||||
continue
|
||||
(prot,role,claim) = kk
|
||||
|
||||
@@ -256,7 +256,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""):
|
||||
involved = set()
|
||||
allkeys = set()
|
||||
for (attackmap,symbs) in attackmaps:
|
||||
for kk in attackmap.keys():
|
||||
for kk in list(attackmap.keys()):
|
||||
allkeys.add(kk)
|
||||
for atl in attackmap[kk]:
|
||||
# convert tuple back to list
|
||||
@@ -298,7 +298,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""):
|
||||
s += "\\hline\n"
|
||||
last = None
|
||||
for kk in sorted(ALLCLAIMS):
|
||||
if kk not in attackmap.keys():
|
||||
if kk not in list(attackmap.keys()):
|
||||
continue
|
||||
(prot,role,claim) = kk
|
||||
|
||||
@@ -313,7 +313,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""):
|
||||
se = tuple([ch])
|
||||
sl += "& "
|
||||
for (attackmap,symb) in attackmaps:
|
||||
if kk in attackmap.keys():
|
||||
if kk in list(attackmap.keys()):
|
||||
if se in attackmap[kk]:
|
||||
sl += symb
|
||||
break
|
||||
@@ -341,7 +341,7 @@ def scanClaimList(fn):
|
||||
fp = open("gen-%s-claims.txt" % (fn),"r")
|
||||
|
||||
claimmap = {}
|
||||
for rawline in fp.xreadlines():
|
||||
for rawline in fp:
|
||||
|
||||
l = rawline.strip()
|
||||
|
||||
@@ -380,7 +380,7 @@ def scanClaimFile(fn):
|
||||
fp = open("gen-%s-correctclaims.tex" % (fn),"r")
|
||||
|
||||
claimmap = {}
|
||||
for rawline in fp.xreadlines():
|
||||
for rawline in fp:
|
||||
|
||||
l = rawline.strip()
|
||||
|
||||
@@ -396,7 +396,7 @@ def scanClaimFile(fn):
|
||||
if not FFUNC(prot):
|
||||
continue
|
||||
|
||||
if prot not in claimmap.keys():
|
||||
if prot not in list(claimmap.keys()):
|
||||
claimmap[prot] = {}
|
||||
|
||||
cll = splitStrip(dtl[1],";")
|
||||
@@ -404,7 +404,7 @@ def scanClaimFile(fn):
|
||||
for dt in cll:
|
||||
(role,claim) = roleClaim(dt)
|
||||
|
||||
if role not in claimmap[prot].keys():
|
||||
if role not in list(claimmap[prot].keys()):
|
||||
claimmap[prot][role] = set()
|
||||
|
||||
claimmap[prot][role].add(claim)
|
||||
@@ -420,7 +420,7 @@ def scanClaimFile(fn):
|
||||
def getRoleClaims(rcmap):
|
||||
|
||||
rc = set()
|
||||
for role in rcmap.keys():
|
||||
for role in list(rcmap.keys()):
|
||||
for claim in rcmap[role]:
|
||||
rc.add((role,claim))
|
||||
|
||||
@@ -459,8 +459,8 @@ def typeScanMatrix(cml,onlyChanged = False):
|
||||
alltrue = True
|
||||
for (txt,cm) in cml:
|
||||
verdict = badverdict
|
||||
if prot in cm.keys():
|
||||
if role in cm[prot].keys():
|
||||
if prot in list(cm.keys()):
|
||||
if role in list(cm[prot].keys()):
|
||||
if claim in cm[prot][role]:
|
||||
verdict = goodverdict
|
||||
if verdict == badverdict:
|
||||
@@ -518,8 +518,8 @@ def typeScanMatrix2(cml,onlyChanged = False,additive = False):
|
||||
res = ""
|
||||
for (txt,cm) in cml:
|
||||
verdict = badverdict
|
||||
if prot in cm.keys():
|
||||
if role in cm[prot].keys():
|
||||
if prot in list(cm.keys()):
|
||||
if role in list(cm[prot].keys()):
|
||||
if claim in cm[prot][role]:
|
||||
verdict = goodverdict
|
||||
if verdict == badverdict:
|
||||
@@ -582,8 +582,8 @@ def typeScanMatrix3(hd1,hd2,cml,f,onlyChanged = False,tabletype="longtable"):
|
||||
resl = []
|
||||
for cm in cml:
|
||||
verdict = badverdict
|
||||
if prot in cm.keys():
|
||||
if role in cm[prot].keys():
|
||||
if prot in list(cm.keys()):
|
||||
if role in list(cm[prot].keys()):
|
||||
if claim in cm[prot][role]:
|
||||
verdict = goodverdict
|
||||
if verdict == badverdict:
|
||||
@@ -660,11 +660,11 @@ def docWrite(fn,tex,author=None,title=None):
|
||||
|
||||
def docMake(fn,tex,author=None,title=None):
|
||||
|
||||
import commands
|
||||
import subprocess
|
||||
|
||||
docWrite(fn,tex,author,title)
|
||||
cmd = "pdflatex %s" % (fn)
|
||||
commands.getoutput(cmd)
|
||||
subprocess.getoutput(cmd)
|
||||
|
||||
def f1(resl):
|
||||
txtl = []
|
||||
|
||||
@@ -32,7 +32,7 @@ def parseArgs():
|
||||
parser.print_help()
|
||||
sys.exit(0)
|
||||
if opts.protocol not in ["nsl","bke","nsl-priv-noprop","nsl-pub-nap","bke-nap"]:
|
||||
print "I don't know the %s protocol." % (opts.protocol)
|
||||
print("I don't know the %s protocol." % (opts.protocol))
|
||||
sys.exit(0)
|
||||
return (opts,args)
|
||||
|
||||
@@ -158,7 +158,7 @@ def message1 (label,inrole):
|
||||
|
||||
return msg
|
||||
else:
|
||||
print "Hmm, I don't know how to create the first message for protocol %s" % (opts.protocol)
|
||||
print("Hmm, I don't know how to create the first message for protocol %s" % (opts.protocol))
|
||||
|
||||
def message2 (label,inrole):
|
||||
global P,variant,opts
|
||||
@@ -205,7 +205,7 @@ def message2 (label,inrole):
|
||||
|
||||
return msg
|
||||
else:
|
||||
print "Hmm, I don't know how to create the final message for protocol %s" % (opts.protocol)
|
||||
print("Hmm, I don't know how to create the final message for protocol %s" % (opts.protocol))
|
||||
|
||||
def message (label,inrole):
|
||||
global P,opts
|
||||
@@ -338,7 +338,7 @@ def main():
|
||||
global opts
|
||||
|
||||
(opts,args) = parseArgs()
|
||||
print protocol(args)
|
||||
print(protocol(args))
|
||||
|
||||
# Only if main stuff
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
# and sincerely hope on gives a complete proof.
|
||||
# we slowly refine the tests.
|
||||
#
|
||||
import commands
|
||||
import subprocess
|
||||
|
||||
def startset():
|
||||
mainlist = [11, 15]
|
||||
print "Starting with", mainlist
|
||||
print("Starting with", mainlist)
|
||||
return mainlist
|
||||
|
||||
def tuplingchoice(heur,variant,P,runs,latupling):
|
||||
@@ -37,15 +37,15 @@ def tuplingchoice(heur,variant,P,runs,latupling):
|
||||
#s += " | scyther -a -r%i --summary" % runs
|
||||
|
||||
# Show what we're doing
|
||||
print s
|
||||
print(s)
|
||||
|
||||
#s += " | grep \"complete\""
|
||||
out = commands.getoutput(s)
|
||||
out = subprocess.getoutput(s)
|
||||
if out == "":
|
||||
#print "Okay"
|
||||
return False
|
||||
else:
|
||||
print out
|
||||
print(out)
|
||||
return True
|
||||
|
||||
def testvariant(h,v,p,r):
|
||||
@@ -55,11 +55,11 @@ def testvariant(h,v,p,r):
|
||||
return tuplingchoice (h,v,p,r, True)
|
||||
|
||||
def scan(testlist, P, runs):
|
||||
print "Testing using P %i and %i runs." % (P,runs)
|
||||
print("Testing using P %i and %i runs." % (P,runs))
|
||||
for i in testlist:
|
||||
print "Testing protocol %i." % (i)
|
||||
print("Testing protocol %i." % (i))
|
||||
for h in range (0,32):
|
||||
print "Heuristic %i:" % (h)
|
||||
print("Heuristic %i:" % (h))
|
||||
testvariant (h,i,P,runs)
|
||||
|
||||
def main():
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
# We test all variants [0..31] until we are sure they work. Thus,
|
||||
# we slowly refine the tests.
|
||||
#
|
||||
import commands
|
||||
import subprocess
|
||||
|
||||
def startset():
|
||||
return range(0,32)
|
||||
return list(range(0,32))
|
||||
|
||||
mainlist = [11, 15]
|
||||
print "Starting with", mainlist
|
||||
print("Starting with", mainlist)
|
||||
return mainlist
|
||||
|
||||
def tuplingchoice(variant,P,runs,latupling):
|
||||
@@ -30,7 +30,7 @@ def tuplingchoice(variant,P,runs,latupling):
|
||||
#s += " | scyther -a -r%i --summary" % runs
|
||||
#print s
|
||||
s += " | grep \"Fail\""
|
||||
out = commands.getoutput(s)
|
||||
out = subprocess.getoutput(s)
|
||||
if out == "":
|
||||
#print "Okay"
|
||||
return True
|
||||
@@ -53,15 +53,15 @@ def removeattacks (testlist, P, runs):
|
||||
return okaylist
|
||||
|
||||
def scan(testlist, P, runs):
|
||||
print "Testing using P %i and %i runs." % (P,runs)
|
||||
print("Testing using P %i and %i runs." % (P,runs))
|
||||
results = removeattacks (testlist, P, runs)
|
||||
if len(results) < len(testlist):
|
||||
attacked = []
|
||||
for i in range(0,len(testlist)):
|
||||
if testlist[i] not in results:
|
||||
attacked.append(testlist[i])
|
||||
print "Using P %i and %i runs, we find attacks on %s" % (P,runs, str(attacked))
|
||||
print "Therefore, we are left with %i candidates: " % (len(results)), results
|
||||
print("Using P %i and %i runs, we find attacks on %s" % (P,runs, str(attacked)))
|
||||
print("Therefore, we are left with %i candidates: " % (len(results)), results)
|
||||
|
||||
return results
|
||||
|
||||
@@ -71,9 +71,9 @@ def main():
|
||||
for rundiff in range(0,5):
|
||||
candidates = scan(candidates,P,P+rundiff)
|
||||
|
||||
print
|
||||
print "Good variants:"
|
||||
print candidates
|
||||
print()
|
||||
print("Good variants:")
|
||||
print(candidates)
|
||||
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user