1
|
|
|
""" |
2
|
|
|
Function for evaluate OVAL operators. |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
|
6
|
1 |
|
def oval_operator_and(result): |
7
|
|
|
"""The AND operator produces a true result if every argument is true. If one or more arguments |
8
|
|
|
are false, the result of the AND is false. If one or more of the arguments are unknown, and |
9
|
|
|
if none of the arguments are false, then the AND operator produces a result of unknown. |
10
|
|
|
|
11
|
|
|
Args: |
12
|
|
|
result (dict): Dictionary representing frequencies of values |
13
|
|
|
|
14
|
|
|
Returns: |
15
|
|
|
str. return values:: |
16
|
|
|
|
17
|
|
|
true |
18
|
|
|
false |
19
|
|
|
error |
20
|
|
|
unknown |
21
|
|
|
noteval |
22
|
|
|
""" |
23
|
1 |
|
out_result = None |
24
|
1 |
|
if (eq_zero(result, 'false_cnt') |
25
|
|
|
and greater_zero(result, 'true_cnt') |
26
|
|
|
and error_unknown_noteval_eq_zero(result)): |
27
|
1 |
|
out_result = 'true' |
28
|
1 |
|
elif greater_zero(result, 'false_cnt'): |
29
|
1 |
|
out_result = 'false' |
30
|
|
|
else: |
31
|
1 |
|
out_result = error_unknown_noteval_for_operators_and_or(result, 'and') |
32
|
1 |
|
return out_result |
33
|
|
|
|
34
|
|
|
|
35
|
1 |
|
def oval_operator_one(result): |
36
|
|
|
"""The ONE operator produces a true result if one and only one argument is true. If there are |
37
|
|
|
more than argument is true (or if there are no true arguments), the result of the ONE |
38
|
|
|
is false. If one or more of the arguments are unknown, then the ONE operator produces |
39
|
|
|
a result of unknown. |
40
|
|
|
|
41
|
|
|
Args: |
42
|
|
|
result (dict): Dictionary representing frequencies of values |
43
|
|
|
|
44
|
|
|
Returns: |
45
|
|
|
str. return values:: |
46
|
|
|
|
47
|
|
|
true |
48
|
|
|
false |
49
|
|
|
error |
50
|
|
|
unknown |
51
|
|
|
noteval |
52
|
|
|
""" |
53
|
1 |
|
out_result = None |
54
|
1 |
|
if one_is_true(result): |
55
|
1 |
|
out_result = 'true' |
56
|
|
|
# Operator ONE has two cases of false |
57
|
1 |
|
elif one_is_false(result) or one_is_false1(result): |
58
|
1 |
|
out_result = 'false' |
59
|
1 |
|
elif one_is_error(result): |
60
|
1 |
|
out_result = 'error' |
61
|
1 |
|
elif one_is_unknown(result): |
62
|
1 |
|
out_result = 'unknown' |
63
|
1 |
|
elif one_is_noteval(result): |
64
|
1 |
|
out_result = 'noteval' |
65
|
1 |
|
return out_result |
66
|
|
|
|
67
|
|
|
|
68
|
1 |
|
def oval_operator_or(result): |
69
|
|
|
"""The OR operator produces a true result if one or more arguments is true. If every argument |
70
|
|
|
is false, the result of the OR is false. If one or more of the arguments are unknown and |
71
|
|
|
if none of arguments are true, then the OR operator produces a result of unknown. |
72
|
|
|
|
73
|
|
|
Args: |
74
|
|
|
result (dict): Dictionary representing frequencies of values |
75
|
|
|
|
76
|
|
|
Returns: |
77
|
|
|
str. return values:: |
78
|
|
|
|
79
|
|
|
true |
80
|
|
|
false |
81
|
|
|
error |
82
|
|
|
unknown |
83
|
|
|
noteval |
84
|
|
|
""" |
85
|
1 |
|
out_result = None |
86
|
1 |
|
if greater_zero(result, 'true_cnt'): |
87
|
1 |
|
out_result = 'true' |
88
|
1 |
|
elif (eq_zero(result, 'true_cnt') |
89
|
|
|
and greater_zero(result, 'false_cnt') |
90
|
|
|
and error_unknown_noteval_eq_zero(result)): |
91
|
1 |
|
out_result = 'false' |
92
|
|
|
else: |
93
|
1 |
|
out_result = error_unknown_noteval_for_operators_and_or(result, 'or') |
94
|
1 |
|
return out_result |
95
|
|
|
|
96
|
|
|
|
97
|
1 |
|
def oval_operator_xor(result): |
98
|
|
|
"""XOR is defined to be true if an odd number of its arguments are true, and false otherwise. |
99
|
|
|
If any of the arguments are unknown, then the XOR operator produces a result of unknown. |
100
|
|
|
|
101
|
|
|
Args: |
102
|
|
|
result (dict): Dictionary representing frequencies of values |
103
|
|
|
|
104
|
|
|
Returns: |
105
|
|
|
str. return values:: |
106
|
|
|
|
107
|
|
|
true |
108
|
|
|
false |
109
|
|
|
error |
110
|
|
|
unknown |
111
|
|
|
noteval |
112
|
|
|
""" |
113
|
1 |
|
out_result = None |
114
|
1 |
|
if ((result['true_cnt'] % 2) == 1 |
115
|
|
|
and eq_zero_unknown_noteval_notappl(result)): |
116
|
1 |
|
out_result = 'true' |
117
|
1 |
|
elif ((result['true_cnt'] % 2) == 0 |
118
|
|
|
and eq_zero_unknown_noteval_notappl(result)): |
119
|
1 |
|
out_result = 'false' |
120
|
1 |
|
elif greater_zero(result, 'error_cnt'): |
121
|
1 |
|
out_result = 'error' |
122
|
1 |
|
elif (eq_zero(result, 'error_cnt') |
123
|
|
|
and greater_zero(result, 'unknown_cnt')): |
124
|
1 |
|
out_result = 'unknown' |
125
|
1 |
|
elif (eq_zero(result, 'error_cnt') |
126
|
|
|
and eq_zero(result, 'unknown_cnt') |
127
|
|
|
and greater_zero(result, 'noteval_cnt')): |
128
|
1 |
|
out_result = 'noteval' |
129
|
1 |
|
return out_result |
130
|
|
|
|
131
|
|
|
|
132
|
1 |
|
def error_unknown_noteval_for_operators_and_or(result, operator): |
|
|
|
|
133
|
|
|
"""Evaluates if the result match the values for error, unknown, noteval. |
134
|
|
|
|
135
|
|
|
Args: |
136
|
|
|
result (dict): Dictionary representing frequencies of values |
137
|
|
|
operator (str): Specifies for which operator is used |
138
|
|
|
|
139
|
|
|
Returns: |
140
|
|
|
str or None. return values:: |
141
|
|
|
|
142
|
|
|
error |
143
|
|
|
unknown |
144
|
|
|
notappl |
145
|
|
|
""" |
146
|
1 |
|
out_result = None |
147
|
1 |
|
value_for_check = 'false_cnt' if operator == 'and' else 'true_cnt' |
148
|
1 |
|
if (eq_zero(result, value_for_check) |
149
|
|
|
and greater_zero(result, 'error_cnt')): |
150
|
1 |
|
out_result = 'error' |
151
|
1 |
|
elif (eq_zero(result, value_for_check) |
152
|
|
|
and error_unknown_eq_zero(result)): |
153
|
1 |
|
out_result = 'unknown' |
154
|
1 |
|
elif (eq_zero(result, value_for_check) |
155
|
|
|
and error_unknown_eq_noteval_greater_zero(result)): |
156
|
1 |
|
out_result = 'noteval' |
157
|
1 |
|
return out_result |
158
|
|
|
|
159
|
|
|
|
160
|
1 |
|
def eq_zero(result, cnt): |
161
|
|
|
"""Evaluates if the value in the result is equal zero. |
162
|
|
|
|
163
|
|
|
Args: |
164
|
|
|
result (dict): Dictionary representing frequencies of values |
165
|
|
|
cnt (str): key for value in result |
166
|
|
|
|
167
|
|
|
Returns: |
168
|
|
|
bool. |
169
|
|
|
""" |
170
|
1 |
|
return result[cnt] == 0 |
171
|
|
|
|
172
|
|
|
|
173
|
1 |
|
def eq_zero_duo(result, cnt0, cnt1): |
174
|
|
|
"""Evaluates if the two values in the result is equal zero. |
175
|
|
|
|
176
|
|
|
Args: |
177
|
|
|
result (dict): Dictionary representing frequencies of values |
178
|
|
|
cnt0 (str): key for value in result |
179
|
|
|
cnt1 (str): key for value in result |
180
|
|
|
|
181
|
|
|
Returns: |
182
|
|
|
bool. |
183
|
|
|
""" |
184
|
1 |
|
return result[cnt0] == 0 and result[cnt1] == 0 |
185
|
|
|
|
186
|
|
|
|
187
|
1 |
|
def greater_zero(result, cnt): |
188
|
|
|
"""Evaluates if the value in the result is greater then zero. |
189
|
|
|
|
190
|
|
|
Args: |
191
|
|
|
result (dict): Dictionary representing frequencies of values |
192
|
|
|
cnt (str): key for value in result |
193
|
|
|
|
194
|
|
|
Returns: |
195
|
|
|
bool. |
196
|
|
|
""" |
197
|
1 |
|
return result[cnt] > 0 |
198
|
|
|
|
199
|
|
|
|
200
|
1 |
|
def eq_or_greater_zero(result, cnt): |
201
|
|
|
"""Evaluates if the value in the result is greater or equal zero. |
202
|
|
|
|
203
|
|
|
Args: |
204
|
|
|
result (dict): Dictionary representing frequencies of values |
205
|
|
|
cnt (str): key for value in result |
206
|
|
|
|
207
|
|
|
Returns: |
208
|
|
|
bool. |
209
|
|
|
""" |
210
|
1 |
|
return result[cnt] >= 0 |
211
|
|
|
|
212
|
|
|
|
213
|
1 |
|
def eq_or_greater_zero_duo(result, cnt0, cnt1): |
214
|
|
|
"""Evaluates if the two values in the result is greater or equal zero. |
215
|
|
|
|
216
|
|
|
Args: |
217
|
|
|
result (dict): Dictionary representing frequencies of values |
218
|
|
|
cnt0 (str): key for value in result |
219
|
|
|
cnt1 (str): key for value in result |
220
|
|
|
|
221
|
|
|
Returns: |
222
|
|
|
bool. |
223
|
|
|
""" |
224
|
1 |
|
return result[cnt0] >= 0 and result[cnt1] >= 0 |
225
|
|
|
|
226
|
|
|
|
227
|
1 |
|
def smaller_than_two(result, cnt): |
228
|
|
|
"""Evaluates if the value in the result is smaller than two. |
229
|
|
|
|
230
|
|
|
Args: |
231
|
|
|
result (dict): Dictionary representing frequencies of values |
232
|
|
|
cnt (str): key for value in result |
233
|
|
|
|
234
|
|
|
Returns: |
235
|
|
|
bool. |
236
|
|
|
""" |
237
|
1 |
|
return result[cnt] < 2 |
238
|
|
|
|
239
|
|
|
|
240
|
1 |
|
def one_is_noteval(result): |
241
|
|
|
"""Evaluates if the result match noteval for one operator. |
242
|
|
|
|
243
|
|
|
Args: |
244
|
|
|
result (dict): Dictionary representing frequencies of values |
245
|
|
|
|
246
|
|
|
Returns: |
247
|
|
|
bool. |
248
|
|
|
""" |
249
|
1 |
|
return (smaller_than_two(result, 'true_cnt') |
250
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'notappl_cnt') |
251
|
|
|
and eq_zero_duo(result, 'error_cnt', 'unknown_cnt') |
252
|
|
|
and greater_zero(result, 'noteval_cnt')) |
253
|
|
|
|
254
|
|
|
|
255
|
1 |
|
def one_is_unknown(result): |
256
|
|
|
"""Evaluates if the result match unknown for one operator. |
257
|
|
|
|
258
|
|
|
Args: |
259
|
|
|
result (dict): Dictionary representing frequencies of values |
260
|
|
|
|
261
|
|
|
Returns: |
262
|
|
|
bool. |
263
|
|
|
""" |
264
|
1 |
|
return (smaller_than_two(result, 'true_cnt') |
265
|
|
|
and eq_or_greater_zero(result, 'false_cnt') |
266
|
|
|
and eq_zero(result, 'error_cnt') |
267
|
|
|
and result['unknown_cnt'] >= 1 |
268
|
|
|
and eq_or_greater_zero_duo(result, 'noteval_cnt', 'notappl_cnt')) |
269
|
|
|
|
270
|
|
|
|
271
|
1 |
|
def one_is_error(result): |
272
|
|
|
"""Evaluates if the result match unknown for one operator. |
273
|
|
|
|
274
|
|
|
Args: |
275
|
|
|
result (dict): Dictionary representing frequencies of values |
276
|
|
|
|
277
|
|
|
Returns: |
278
|
|
|
bool. |
279
|
|
|
""" |
280
|
1 |
|
return (smaller_than_two(result, 'true_cnt') |
281
|
|
|
and eq_or_greater_zero(result, 'false_cnt') |
282
|
|
|
and greater_zero(result, 'error_cnt') |
283
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result)) |
284
|
|
|
|
285
|
|
|
|
286
|
1 |
|
def one_is_false(result): |
287
|
|
|
"""Evaluates if the result match false for one operator. |
288
|
|
|
|
289
|
|
|
Args: |
290
|
|
|
result (dict): Dictionary representing frequencies of values |
291
|
|
|
|
292
|
|
|
Returns: |
293
|
|
|
bool. |
294
|
|
|
""" |
295
|
1 |
|
return (eq_zero(result, 'true_cnt') |
296
|
|
|
and eq_or_greater_zero(result, 'false_cnt') |
297
|
|
|
and error_unknown_noteval_eq_zero(result) |
298
|
|
|
and result['notappl_cnt'] >= 0) |
299
|
|
|
|
300
|
|
|
|
301
|
1 |
|
def one_is_false1(result): |
302
|
|
|
"""Evaluates if the result match false for one operator. |
303
|
|
|
|
304
|
|
|
Args: |
305
|
|
|
result (dict): Dictionary representing frequencies of values |
306
|
|
|
|
307
|
|
|
Returns: |
308
|
|
|
bool. |
309
|
|
|
""" |
310
|
1 |
|
return (result['true_cnt'] >= 2 |
311
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'error_cnt') |
312
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result)) |
313
|
|
|
|
314
|
|
|
|
315
|
1 |
|
def one_is_true(result): |
316
|
|
|
"""Evaluates if the result match true for one operator. |
317
|
|
|
|
318
|
|
|
Args: |
319
|
|
|
result (dict): Dictionary representing frequencies of values |
320
|
|
|
|
321
|
|
|
Returns: |
322
|
|
|
bool. |
323
|
|
|
""" |
324
|
1 |
|
return (result['true_cnt'] == 1 |
325
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'notappl_cnt') |
326
|
|
|
and error_unknown_noteval_eq_zero(result)) |
327
|
|
|
|
328
|
|
|
|
329
|
1 |
|
def eq_or_greater_zero_unknown_noteval_notappl(result): |
|
|
|
|
330
|
|
|
"""Evaluates if counts of values unknown, |
331
|
|
|
noteval and notappl in result are equal or greater zero. |
332
|
|
|
|
333
|
|
|
Args: |
334
|
|
|
result (dict): Dictionary representing frequencies of values |
335
|
|
|
|
336
|
|
|
Returns: |
337
|
|
|
bool. |
338
|
|
|
""" |
339
|
1 |
|
return (eq_or_greater_zero(result, 'unknown_cnt') |
340
|
|
|
and eq_or_greater_zero(result, 'noteval_cnt') |
341
|
|
|
and eq_or_greater_zero(result, 'notappl_cnt')) |
342
|
|
|
|
343
|
|
|
|
344
|
1 |
|
def eq_zero_unknown_noteval_notappl(result): |
345
|
|
|
"""Evaluates if counts of values error, |
346
|
|
|
unknown and noteval in result are equal zero. |
347
|
|
|
|
348
|
|
|
Args: |
349
|
|
|
result (dict): Dictionary representing frequencies of values |
350
|
|
|
|
351
|
|
|
Returns: |
352
|
|
|
bool. |
353
|
|
|
""" |
354
|
1 |
|
return (eq_zero(result, 'error_cnt') |
355
|
|
|
and eq_zero(result, 'unknown_cnt') |
356
|
|
|
and eq_zero(result, 'noteval_cnt')) |
357
|
|
|
|
358
|
|
|
|
359
|
1 |
|
def error_unknown_noteval_eq_zero(result): |
360
|
|
|
"""Evaluates if counts of values error, |
361
|
|
|
noteval and unknown in result are equal zero. |
362
|
|
|
|
363
|
|
|
Args: |
364
|
|
|
result (dict): Dictionary representing frequencies of values |
365
|
|
|
|
366
|
|
|
Returns: |
367
|
|
|
bool. |
368
|
|
|
""" |
369
|
1 |
|
return (eq_zero(result, 'error_cnt') |
370
|
|
|
and eq_zero(result, 'unknown_cnt') |
371
|
|
|
and eq_zero(result, 'noteval_cnt')) |
372
|
|
|
|
373
|
|
|
|
374
|
1 |
|
def error_unknown_eq_noteval_greater_zero(result): |
|
|
|
|
375
|
|
|
"""Evaluates if counts of values in result for unknown, |
376
|
|
|
error are equal zero and for noteval is greater than zero. |
377
|
|
|
|
378
|
|
|
Args: |
379
|
|
|
result (dict): Dictionary representing frequencies of values |
380
|
|
|
|
381
|
|
|
Returns: |
382
|
|
|
bool. |
383
|
|
|
""" |
384
|
1 |
|
return (eq_zero(result, 'error_cnt') |
385
|
|
|
and eq_zero(result, 'unknown_cnt') |
386
|
|
|
and greater_zero(result, 'noteval_cnt')) |
387
|
|
|
|
388
|
|
|
|
389
|
1 |
|
def error_unknown_eq_zero(result): |
390
|
|
|
"""Evaluates if counts of values in result for |
391
|
|
|
error is equal zero and for unknown is greater than zero. |
392
|
|
|
|
393
|
|
|
Args: |
394
|
|
|
result (dict): Dictionary representing frequencies of values |
395
|
|
|
|
396
|
|
|
Returns: |
397
|
|
|
bool. |
398
|
|
|
""" |
399
|
1 |
|
return (eq_zero(result, 'error_cnt') |
400
|
|
|
and greater_zero(result, 'unknown_cnt')) |
401
|
|
|
|
402
|
|
|
|
403
|
1 |
|
def is_notapp_result(result): |
404
|
|
|
"""Evaluates if the counts of values in |
405
|
|
|
the result matches the notapp result. |
406
|
|
|
|
407
|
|
|
Args: |
408
|
|
|
result (dict): Dictionary representing frequencies of values |
409
|
|
|
|
410
|
|
|
Returns: |
411
|
|
|
bool. |
412
|
|
|
""" |
413
|
1 |
|
return (result['notappl_cnt'] > 0 |
414
|
|
|
and eq_zero(result, 'false_cnt') |
415
|
|
|
and error_unknown_noteval_eq_zero(result) |
416
|
|
|
and eq_zero(result, 'true_cnt')) |
417
|
|
|
|
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.