Skip to content

Commit 149785d

Browse files
authored
Merge pull request #1402 from yuumasato/swig_object_string_representation
SWIG openscap_api: Use __repr__() to get consistent string output
2 parents 52be17e + b1229e8 commit 149785d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

swig/openscap_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
__version__ = '1.0'
2828

2929
import logging # Logger for debug/info/error messages
30+
import re
3031
logger = logging.getLogger("openscap")
3132

3233
from sys import version_info
@@ -135,8 +136,9 @@ def __init__(self, object, instance=None):
135136
@staticmethod
136137
def new(retobj):
137138
if type(retobj).__name__ in ('SwigPyObject', 'PySwigObject'):
138-
# Extract the name of structure from "<num>_p_<name>"
139-
structure = retobj.__str__()[retobj.__str__().find("_p_")+3:]
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]
140142
return OSCAP_Object(structure, retobj)
141143
else:
142144
return retobj

0 commit comments

Comments
 (0)