Skip to content

Commit fa64fb5

Browse files
fix contructor call handling
1 parent a75329b commit fa64fb5

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

swig/openscap_api.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,13 @@ def __getattr__(self, name):
273273
except:
274274
return self.__func_wrapper(obj)
275275

276-
""" There is not function with the name 'name' let return the OSCAP_Object
277-
This should return None, why is this here ?
278-
"""
276+
""" Looking if it's can be a constructor """
277+
obj = OSCAP.__dict__.get(self.object + "_" + name + "_new")
278+
if obj is not None:
279+
# this will call the __call__ definition of OSCAP_Object
280+
return OSCAP_Object(self.object + "_" + name)
281+
282+
""" There is not function with the name 'name' let return the OSCAP_Object """
279283
raise AttributeError("Attribute {0} not found for object {1}"
280284
.format(name, self.object))
281285

@@ -316,6 +320,7 @@ def __call__(self, *args, **kwargs):
316320
# It's maybe looking for "new" ?
317321
obj = OSCAP.__dict__.get(self.object + "_new")
318322
if obj is not None:
323+
print("obj not none !")
319324
return OSCAP_Object.new(obj(*newargs))
320325
else:
321326
raise NameError("name '" + self.object + "' is not defined")
@@ -480,21 +485,19 @@ def get_values_by_rule_id(self, id, check=None):
480485

481486
return items
482487

483-
484488
def __parse_value(self, value):
485489
''' Used by get_tailoring_items() '''
486-
490+
487491
# update the local lang lists
488492
def __update_lang(item, lang):
489493
if lang not in item["langs"]:
490494
item["langs"].add(lang)
491-
492-
495+
493496
# get value properties
494497
item = {}
495498
item["id"] = value.id
496-
item["langs"] = {self.model.benchmark.lang} # set of available langs
497-
item["lang"] = self.model.benchmark.lang # legacy support of item["lang"]
499+
item["langs"] = {self.model.benchmark.lang} # set of available langs
500+
item["lang"] = self.model.benchmark.lang # legacy support of item["lang"]
498501
item["titles"] = {}
499502
item["descs"] = {}
500503
# Titles / Questions
@@ -505,7 +508,7 @@ def __update_lang(item, lang):
505508
for title in value.title:
506509
__update_lang(item, title.lang)
507510
item["titles"][title.lang] = title.text
508-
511+
509512
if item["lang"] not in item["titles"]:
510513
item["titles"][item["lang"]] = ""
511514
# Descriptions
@@ -617,12 +620,13 @@ def set_tailor_items(self, items):
617620
selector = None
618621
value = self.model.benchmark.item(item["id"]).to_value()
619622
for instance in value.instances:
623+
print("item = {0}".format(instance.value))
620624
if item["value"] == instance.value:
621625
selector = instance.selector
622626

623627
oper = remarks = setvalue = None
624628
for r_value in self.profile.refine_values[:]:
625-
if r_value.item == item["id"]:
629+
if r_value.item == item["id"] and r_value in self.profile.refine_values:
626630
oper = r_value.oper
627631
remarks = r_value.remarks
628632
self.profile.refine_values.remove(r_value)

0 commit comments

Comments
 (0)