From cc204475ff3353b3af654bcd3b2b09fe5c466170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 10 Oct 2019 18:33:55 +0200 Subject: [PATCH] chg: Test if json exists in cached method --- pymisp/abstract.py | 4 ++++ pymisp/mispevent.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pymisp/abstract.py b/pymisp/abstract.py index 6b13143..eca520f 100644 --- a/pymisp/abstract.py +++ b/pymisp/abstract.py @@ -60,6 +60,8 @@ if sys.version_info < (3, 0): @staticmethod @cached(cache=LRUCache(maxsize=150)) def _load_json(path): + if not os.path.exists(path): + return None with open(path, 'r') as f: data = load(f) return data @@ -80,6 +82,8 @@ else: @staticmethod @lru_cache(maxsize=150) def _load_json(path): + if not path.exists(): + return None with path.open('r') as f: data = load(f) return data diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index 47e4cf5..36f70cd 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -1177,9 +1177,9 @@ class MISPObject(AbstractMISP): self.update_not_jsonable('ObjectReference') def _load_template_path(self, template_path): - if not os.path.exists(template_path): - return False self._definition = self._load_json(template_path) + if not self._definition: + return False setattr(self, 'meta-category', self._definition['meta-category']) self.template_uuid = self._definition['uuid'] self.description = self._definition['description']