cti-python-stix2/stix2/__init__.py

34 lines
899 B
Python
Raw Normal View History

2017-02-10 22:35:02 +01:00
"""Python APIs for STIX 2."""
2017-01-17 21:37:47 +01:00
2017-03-22 14:05:59 +01:00
# flake8: noqa
2017-04-05 23:12:44 +02:00
import json
2017-02-10 22:35:02 +01:00
from .bundle import Bundle
2017-02-24 19:51:21 +01:00
from .common import ExternalReference, KillChainPhase
2017-02-24 18:56:55 +01:00
from .sdo import AttackPattern, Campaign, CourseOfAction, Identity, Indicator, \
IntrusionSet, Malware, ObservedData, Report, ThreatActor, Tool, \
Vulnerability
from .sro import Relationship, Sighting
from .markings import MarkingDefinition, GranularMarking, StatementMarking, TLPMarking
2017-04-05 23:12:44 +02:00
def parse(data):
"""Deserialize a string or file-like object into a STIX object"""
if type(data) is dict:
obj = data
else:
try:
obj = json.loads(data)
except TypeError:
obj = json.load(data)
2017-04-05 23:12:44 +02:00
if 'type' not in obj:
# TODO parse external references, kill chain phases, and granular markings
pass
elif obj['type'] == 'malware':
return sdo.Malware(**obj)
return obj