fix: Python <3.4 should work again....

Fix #482
pull/485/head
Raphaël Vinot 2019-10-18 11:56:05 +02:00
parent 21c16c8c75
commit fef328d395
2 changed files with 24 additions and 2 deletions

View File

@ -66,6 +66,28 @@ if sys.version_info < (3, 0):
data = load(f)
return data
elif sys.version_info < (3, 4):
from collections.abc import MutableMapping
from functools import lru_cache
import os
resources_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
misp_objects_path = os.path.join(resources_path, 'misp-objects', 'objects')
with open(os.path.join(resources_path, 'describeTypes.json'), 'r') as f:
describe_types = load(f)['result']
class MISPFileCache(object):
# cache up to 150 JSON structures in class attribute
@staticmethod
@lru_cache(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
else:
from collections.abc import MutableMapping
from functools import lru_cache

View File

@ -427,7 +427,7 @@ class MISPEvent(AbstractMISP):
schema_file = 'schema.json'
else:
schema_file = 'schema-lax.json'
if sys.version_info >= (3, 6):
if sys.version_info >= (3, 4):
self.__json_schema = self._load_json(self.resources_path / schema_file)
else:
self.__json_schema = self._load_json(os.path.join(self.resources_path, schema_file))
@ -1211,7 +1211,7 @@ class MISPObject(AbstractMISP):
self.misp_objects_path = misp_objects_path_custom
# Try to get the template
if sys.version_info >= (3, 6):
if sys.version_info >= (3, 4):
self._known_template = self._load_template_path(self.misp_objects_path / self.name / 'definition.json')
else:
self._known_template = self._load_template_path(os.path.join(self.misp_objects_path, self.name, 'definition.json'))