mirror of https://github.com/MISP/PyTaxonomies
new: Add exclusive flag at taxonomy and predicate level
Bump misp-taxonomiespull/6/head
parent
b7fb91fbe9
commit
b46a96e0e6
|
@ -63,6 +63,7 @@ class Predicate(collections.Mapping):
|
||||||
self.expanded = predicate.get('expanded')
|
self.expanded = predicate.get('expanded')
|
||||||
self.description = predicate.get('description')
|
self.description = predicate.get('description')
|
||||||
self.colour = predicate.get('colour')
|
self.colour = predicate.get('colour')
|
||||||
|
self.exclusive = predicate.get('exclusive')
|
||||||
self.__init_entries(entries)
|
self.__init_entries(entries)
|
||||||
|
|
||||||
def __init_entries(self, entries):
|
def __init_entries(self, entries):
|
||||||
|
@ -79,11 +80,12 @@ class Predicate(collections.Mapping):
|
||||||
to_return['description'] = self.description
|
to_return['description'] = self.description
|
||||||
if self.colour:
|
if self.colour:
|
||||||
to_return['colour'] = self.colour
|
to_return['colour'] = self.colour
|
||||||
|
if self.exclusive:
|
||||||
|
to_return['exclusive'] = self.exclusive
|
||||||
if self.entries:
|
if self.entries:
|
||||||
to_return['entries'] = self.values()
|
to_return['entries'] = self.values()
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return json.dumps(self, cls=EncodeTaxonomies)
|
return json.dumps(self, cls=EncodeTaxonomies)
|
||||||
|
|
||||||
|
@ -110,6 +112,7 @@ class Taxonomy(collections.Mapping):
|
||||||
self.expanded = self.taxonomy.get('expanded')
|
self.expanded = self.taxonomy.get('expanded')
|
||||||
self.refs = self.taxonomy.get('refs')
|
self.refs = self.taxonomy.get('refs')
|
||||||
self.type = self.taxonomy.get('type')
|
self.type = self.taxonomy.get('type')
|
||||||
|
self.exclusive = self.taxonomy.get('exclusive')
|
||||||
self.__init_predicates()
|
self.__init_predicates()
|
||||||
|
|
||||||
def __init_predicates(self):
|
def __init_predicates(self):
|
||||||
|
@ -135,13 +138,14 @@ class Taxonomy(collections.Mapping):
|
||||||
to_return['refs'] = self.refs
|
to_return['refs'] = self.refs
|
||||||
if self.type:
|
if self.type:
|
||||||
to_return['type'] = self.type
|
to_return['type'] = self.type
|
||||||
|
if self.exclusive:
|
||||||
|
to_return['exclusive'] = self.exclusive
|
||||||
predicates = [p.to_dict() for p in self.values()]
|
predicates = [p.to_dict() for p in self.values()]
|
||||||
entries = []
|
entries = []
|
||||||
for p in predicates:
|
for p in predicates:
|
||||||
if p.get('entries') is None:
|
if p.get('entries') is None:
|
||||||
continue
|
continue
|
||||||
entries.append({'predicate': p['value'],
|
entries.append({'predicate': p['value'], 'entry': [e.to_dict() for e in p.pop('entries')]})
|
||||||
'entry': [e.to_dict() for e in p.pop('entries')]})
|
|
||||||
to_return['predicates'] = predicates
|
to_return['predicates'] = predicates
|
||||||
if entries:
|
if entries:
|
||||||
to_return['values'] = entries
|
to_return['values'] = entries
|
||||||
|
@ -223,8 +227,7 @@ class Taxonomies(collections.Mapping):
|
||||||
def validate_with_schema(self):
|
def validate_with_schema(self):
|
||||||
if not HAS_JSONSCHEMA:
|
if not HAS_JSONSCHEMA:
|
||||||
raise ImportError('jsonschema is required: pip install jsonschema')
|
raise ImportError('jsonschema is required: pip install jsonschema')
|
||||||
schema = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pytaxonomies'].__file__)),
|
schema = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pytaxonomies'].__file__)), 'data', 'misp-taxonomies', 'schema.json')
|
||||||
'data', 'misp-taxonomies', 'schema.json')
|
|
||||||
with open(schema, 'r') as f:
|
with open(schema, 'r') as f:
|
||||||
loaded_schema = json.load(f)
|
loaded_schema = json.load(f)
|
||||||
for t in self.values():
|
for t in self.values():
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a5f77f2ee0c8f1294edc23e30f4c075bbf404504
|
Subproject commit f97d3f0339572e3199dd4cb23a43813d7254ac94
|
Loading…
Reference in New Issue