@@ -56,6 +56,13 @@ def _import_helper():
56
56
57
57
import os
58
58
59
+
60
+ def extract_type_from_obj (obj ):
61
+ # Extract the name of structure from the representation of the object
62
+ # "<Swig Object of type 'struct xccdf_result_iterator *' at 0x7f8f65fc1390>"
63
+ # or "<Swig Object of type 'oval_agent_session_t *' at 0x7f9aa2cdf360>"
64
+ return re .findall (r"type '(struct )?(\b\S*\b)" , obj .__repr__ ())[0 ][1 ]
65
+
59
66
class OSCAP_List (list ):
60
67
"""OSCAP List class is designed to store lists generated from openscap iterators. All functions that return iterators
61
68
are preprocessed by creation of OSCAP List instance and move all objects given by oscap list iteration loop to list.
@@ -136,10 +143,7 @@ def __init__(self, object, instance=None):
136
143
@staticmethod
137
144
def new (retobj ):
138
145
if type (retobj ).__name__ in ('SwigPyObject' , 'PySwigObject' ):
139
- # Extract the name of structure from the representation of the object
140
- # "<Swig Object of type 'struct xccdf_result_iterator *' at 0x7f8f65fc1390>"
141
- structure = re .findall (r"type 'struct (\b\S*\b)" , retobj .__repr__ ())[0 ]
142
- return OSCAP_Object (structure , retobj )
146
+ return OSCAP_Object (extract_type_from_obj (retobj ), retobj )
143
147
else :
144
148
return retobj
145
149
@@ -320,8 +324,10 @@ def free(self):
320
324
def __start_callback (self , rule , obj ):
321
325
return obj [0 ](OSCAP_Object ("xccdf_rule" , rule ), obj [1 ])
322
326
323
- def __output_callback (self , rule_result , obj ):
324
- return obj [0 ](OSCAP_Object ("xccdf_rule_result" , rule_result ), obj [1 ])
327
+ def __output_callback (self , result , obj ):
328
+ # the returned object can be a rule_result or an oval_definition_result,
329
+ # so I extract the right name from the object repr.
330
+ return obj [0 ](OSCAP_Object (extract_type_from_obj (result ), result ), obj [1 ])
325
331
326
332
def register_start_callback (self , cb , usr ):
327
333
if self .object != "xccdf_policy_model" :
0 commit comments