From 6d2576be0ab1183d0b12d37b4a1e953565bc661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 26 Sep 2017 10:52:38 +0100 Subject: [PATCH] fix: Allow again to tag/delete unsaved attributes --- pymisp/mispevent.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index b5b0d74..cc4c74a 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -514,15 +514,17 @@ class MISPEvent(AbstractMISP): self.Tag.append({'name': tag}) def add_attribute_tag(self, tag, attribute_identifier): - attribute = None + attributes = [] for a in self.attributes: - if (a.id == attribute_identifier or a.uuid == attribute_identifier or - attribute_identifier == a.value or attribute_identifier in a.value.split('|')): + if ((hasattr(a, 'id') and a.id == attribute_identifier) or + (hasattr(a, 'uuid') and a.uuid == attribute_identifier) or + (hasattr(a, 'value') and attribute_identifier == a.value or + attribute_identifier in a.value.split('|'))): a.add_tag(tag) - attribute = a - if not attribute: + attributes.append(a) + if not attributes: raise Exception('No attribute with identifier {} found.'.format(attribute_identifier)) - return attribute + return attributes def publish(self): self.published = True @@ -533,7 +535,8 @@ class MISPEvent(AbstractMISP): def delete_attribute(self, attribute_id): found = False for a in self.attributes: - if a.id == attribute_id or a.uuid == attribute_id: + if ((hasattr(a, 'id') and a.id == attribute_id) or + (hasattr(a, 'uuid') and a.uuid == attribute_id)): a.delete() found = True break