chg: Test if json exists in cached method

pull/475/head
Raphaël Vinot 2019-10-10 18:33:55 +02:00
parent 6cc7730d24
commit cc204475ff
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

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