Skip to content

Commit 6b4b30a

Browse files
authored
Merge pull request #1406 from DominiqueDevinci/contrib
SWIG Python : bug fixes related to the internal object type
2 parents 149785d + 43631cb commit 6b4b30a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

swig/openscap_api.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def _import_helper():
5656

5757
import os
5858

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+
5966
class OSCAP_List(list):
6067
"""OSCAP List class is designed to store lists generated from openscap iterators. All functions that return iterators
6168
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):
136143
@staticmethod
137144
def new(retobj):
138145
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)
143147
else:
144148
return retobj
145149

@@ -320,8 +324,10 @@ def free(self):
320324
def __start_callback(self, rule, obj):
321325
return obj[0](OSCAP_Object("xccdf_rule", rule), obj[1])
322326

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])
325331

326332
def register_start_callback(self, cb, usr):
327333
if self.object != "xccdf_policy_model":

0 commit comments

Comments
 (0)