@@ -78,15 +78,36 @@ def remove(self, item):
78
78
"""Function to remove item from list. This removed item should be also
79
79
removed from parent oscap list. This function is supported only if there exists
80
80
reset function on iterators. Exception is throwed otherwise."""
81
-
82
81
try :
83
82
self .iterator .reset ()
84
83
while self .iterator .has_more ():
85
84
litem = self .iterator .next ()
86
85
if (type (item ) == str and type (litem ) == str and litem == item ) or \
87
86
("instance" in item .__dict__ and litem .instance == item .instance ):
87
+
88
88
self .iterator .remove ()
89
- list .remove (self , item )
89
+
90
+
91
+ '''
92
+ Warning, list.remove(self, item) will fail because python yield
93
+ a new reference at each loop. So wee need to loop again into the python list,
94
+ get the new reference and remove it. Demo:
95
+
96
+ print(item.instance)
97
+ print(litem.instance)
98
+ print(litem.instance == item.instance)
99
+
100
+ RETURNS:
101
+
102
+ <Swig Object of type 'struct xccdf_refine_value *' at 0x7ff85ed73bd0>
103
+ <Swig Object of type 'struct xccdf_refine_value *' at 0x7ff85ed73c90>
104
+ True
105
+ '''
106
+
107
+ for i in self [:]:
108
+ if "instance" in item .__dict__ and i .instance == item .instance :
109
+ list .remove (self , i )
110
+
90
111
except NameError :
91
112
raise Exception ("Removing %s items throught oscap list is not allowed. "
92
113
"Please use appropriate function."
@@ -103,6 +124,8 @@ def generate(self, iterator):
103
124
104
125
while iterator .has_more ():
105
126
list .append (self , iterator .next ())
127
+
128
+
106
129
107
130
def append (self , item , n = 1 ):
108
131
"""This function is not allowed. Please use appropriate function from library."""
@@ -623,10 +646,11 @@ def set_tailor_items(self, items):
623
646
624
647
oper = remarks = setvalue = None
625
648
for r_value in self .profile .refine_values [:]:
626
- if r_value .item == item ["id" ] and r_value in self . profile . refine_values :
649
+ if r_value .item == item ["id" ]:
627
650
oper = r_value .oper
628
651
remarks = r_value .remarks
629
652
self .profile .refine_values .remove (r_value )
653
+
630
654
for s_value in self .profile .setvalues [:]:
631
655
if s_value .item == item ["id" ]:
632
656
setvalue = s_value .value
0 commit comments