/
ddmin .py
executable file
·113 lines (62 loc) · 1.68 KB
/
ddmin .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import sys,outputters
from split import split
from xml.parsers.xmlproc import xmlval,xmlproc
from listsets import listminus
PASS = "PASS"
FAIL = "FAIL"
UNRESOLVED = "UNRESOLVED"
MAX_DEGREE = 5
def ddmin(data, test,n=1):
"""Return a sublist of CIRCUMSTANCES that is a relevant configuration
with respect to TEST."""
subsets=split(data,n)
for subset in subsets:
if test(subset)==FAIL:
return ddmin(subset,test,2)
return tempfile()
if __name__ == "__main__":
tests = {}
warnings=1
entstack=0
rawxml=0
fname = sys.argv[1]
file1 = open(fname, 'r')
data = file1.read()
file1.close()
app = xmlproc.Application()
p = xmlproc.XMLProcessor()
p.set_application(app)
err=outputters.MyErrorHandler(p, p, warnings, entstack, rawxml)
p.set_error_handler(err)
def getfile(s):
temp=open('temp.xml','w+')
temp.write(s)
temp.flush()
temp.close()
return temp.name
def tempfile():
temp=open('temp.xml','r')
data=temp.read()
temp.close()
return data
def test(c):
global tests
s= ""
for char in c:
s += char
if s in tests.keys():
return tests[s]
try:
p.set_data_after_wf_error(0)
p.parse_resource(getfile(c))
except SyntaxError:
tests[s] = UNRESOLVED
return UNRESOLVED
except UnboundLocalError:
print FAIL
tests[s] = FAIL
return FAIL
else :
tests[s] = PASS
return PASS
failed=ddmin(data,test)