From e359f225752466833bc40b950947a4e4c9e6e2ce Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Fri, 16 Feb 2018 09:47:07 +0100 Subject: [PATCH 1/2] new: Method to return an object by uuid --- pymisp/mispevent.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index 5d96719..7620ba9 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -618,7 +618,14 @@ class MISPEvent(AbstractMISP): for obj in self.objects: if hasattr(obj, 'id') and int(obj.id) == int(object_id): return obj - raise InvalidMISPObject('Object with {} does not exists in ths event'.format(object_id)) + raise InvalidMISPObject('Object with {} does not exist in this event'.format(object_id)) + + def get_object_by_uuid(self, object_uuid): + """Get an object by UUID (UUID is set by the server when creating the new object)""" + for obj in self.objects: + if hasattr(obj, 'id') and obj.uuid == object_uuid: + return obj + raise InvalidMISPObject('Object with {} does not exist in this event'.format(object_uuid)) def add_object(self, obj=None, **kwargs): """Add an object to the Event, either by passing a MISPObject, or a dictionary""" From cc9395db99d76845bb209a5d85f4ff91997054a2 Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Mon, 19 Feb 2018 09:16:27 +0100 Subject: [PATCH 2/2] fix: typo --- pymisp/mispevent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index 7620ba9..e23946f 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -623,7 +623,7 @@ class MISPEvent(AbstractMISP): def get_object_by_uuid(self, object_uuid): """Get an object by UUID (UUID is set by the server when creating the new object)""" for obj in self.objects: - if hasattr(obj, 'id') and obj.uuid == object_uuid: + if hasattr(obj, 'uuid') and obj.uuid == object_uuid: return obj raise InvalidMISPObject('Object with {} does not exist in this event'.format(object_uuid))