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']