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