Sort imports.

stix2.1
Emmanuelle Vargas-Gonzalez 2018-06-26 12:23:53 -04:00
parent 5cbe886cdb
commit 9baaad6e08
14 changed files with 40 additions and 43 deletions

View File

@ -56,7 +56,7 @@ class STIXJSONIncludeOptionalDefaultsEncoder(json.JSONEncoder):
elif isinstance(obj, _STIXBase): elif isinstance(obj, _STIXBase):
return dict(obj) return dict(obj)
else: else:
return super(STIXJSONEncoder, self).default(obj) return super(STIXJSONIncludeOptionalDefaultsEncoder, self).default(obj)
def get_required_properties(properties): def get_required_properties(properties):

View File

@ -2,8 +2,7 @@ import importlib
import pkgutil import pkgutil
import stix2 import stix2
from .exceptions import ParseError
from . import exceptions
from .utils import _get_dict from .utils import _get_dict
STIX2_OBJ_MAPS = {} STIX2_OBJ_MAPS = {}
@ -74,7 +73,7 @@ def dict_to_stix2(stix_dict, allow_custom=False, version=None):
""" """
if 'type' not in stix_dict: if 'type' not in stix_dict:
raise exceptions.ParseError("Can't parse object with no 'type' property: %s" % str(stix_dict)) raise ParseError("Can't parse object with no 'type' property: %s" % str(stix_dict))
if "spec_version" in stix_dict: if "spec_version" in stix_dict:
# For STIX 2.0, applies to bundles only. # For STIX 2.0, applies to bundles only.
@ -87,7 +86,7 @@ def dict_to_stix2(stix_dict, allow_custom=False, version=None):
else: else:
v = 'v' + stix2.DEFAULT_VERSION.replace('.', '') v = 'v' + stix2.DEFAULT_VERSION.replace('.', '')
else: else:
v = 'v20' v = 'v' + stix2.DEFAULT_VERSION.replace('.', '')
OBJ_MAP = STIX2_OBJ_MAPS[v] OBJ_MAP = STIX2_OBJ_MAPS[v]
@ -98,7 +97,7 @@ def dict_to_stix2(stix_dict, allow_custom=False, version=None):
# flag allows for unknown custom objects too, but will not # flag allows for unknown custom objects too, but will not
# be parsed into STIX object, returned as is # be parsed into STIX object, returned as is
return stix_dict return stix_dict
raise exceptions.ParseError("Can't parse unknown object type '%s'! For custom types, use the CustomObject decorator." % stix_dict['type']) raise ParseError("Can't parse unknown object type '%s'! For custom types, use the CustomObject decorator." % stix_dict['type'])
return obj_class(allow_custom=allow_custom, **stix_dict) return obj_class(allow_custom=allow_custom, **stix_dict)

View File

@ -1,10 +1,10 @@
from collections import OrderedDict from collections import OrderedDict
from stix2 import parse from ..base import _STIXBase
from stix2.base import _STIXBase from ..core import parse
from .properties import (IDProperty, ListProperty, Property, from ..utils import _get_dict, get_class_hierarchy_names
StringProperty, TypeProperty) from .properties import (IDProperty, ListProperty, Property, StringProperty,
from stix2.utils import _get_dict, get_class_hierarchy_names TypeProperty)
class STIXObjectProperty(Property): class STIXObjectProperty(Property):

View File

@ -4,10 +4,10 @@ from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..utils import NOW, _get_dict
from .properties import (HashesProperty, IDProperty, ListProperty, Property, from .properties import (HashesProperty, IDProperty, ListProperty, Property,
ReferenceProperty, SelectorProperty, StringProperty, ReferenceProperty, SelectorProperty, StringProperty,
TimestampProperty, TypeProperty) TimestampProperty, TypeProperty)
from ..utils import NOW, _get_dict
class ExternalReference(_STIXBase): class ExternalReference(_STIXBase):

View File

@ -12,12 +12,12 @@ import re
from ..base import _Extension, _Observable, _STIXBase from ..base import _Extension, _Observable, _STIXBase
from ..exceptions import (AtLeastOnePropertyError, CustomContentError, from ..exceptions import (AtLeastOnePropertyError, CustomContentError,
DependentPropertiesError, ParseError) DependentPropertiesError, ParseError)
from ..utils import TYPE_REGEX, _get_dict
from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty, from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, FloatProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty,
HashesProperty, HexProperty, IntegerProperty, HashesProperty, HexProperty, IntegerProperty,
ListProperty, ObjectReferenceProperty, Property, ListProperty, ObjectReferenceProperty, Property,
StringProperty, TimestampProperty, TypeProperty) StringProperty, TimestampProperty, TypeProperty)
from ..utils import TYPE_REGEX, _get_dict
class ObservableProperty(Property): class ObservableProperty(Property):

View File

@ -10,9 +10,9 @@ import uuid
from six import string_types, text_type from six import string_types, text_type
from stix2patterns.validator import run_validator from stix2patterns.validator import run_validator
from stix2.base import _STIXBase from ..base import _STIXBase
from stix2.exceptions import DictionaryKeyError from ..exceptions import DictionaryKeyError
from stix2.utils import _get_dict, parse_into_datetime from ..utils import _get_dict, parse_into_datetime
class Property(object): class Property(object):

View File

@ -4,16 +4,15 @@
from collections import OrderedDict from collections import OrderedDict
import re import re
import stix2
from ..base import _STIXBase from ..base import _STIXBase
from ..core import _register_type
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from .properties import (BooleanProperty, IDProperty, IntegerProperty,
ListProperty, PatternProperty, ReferenceProperty,
StringProperty, TimestampProperty, TypeProperty)
from ..utils import NOW, TYPE_REGEX from ..utils import NOW, TYPE_REGEX
from .common import ExternalReference, GranularMarking, KillChainPhase from .common import ExternalReference, GranularMarking, KillChainPhase
from .observables import ObservableProperty from .observables import ObservableProperty
from .properties import (BooleanProperty, IDProperty, IntegerProperty,
ListProperty, PatternProperty, ReferenceProperty,
StringProperty, TimestampProperty, TypeProperty)
class STIXDomainObject(_STIXBase, _MarkingsMixin): class STIXDomainObject(_STIXBase, _MarkingsMixin):
@ -409,7 +408,7 @@ def CustomObject(type='x-custom-type', properties=None):
return return
raise e raise e
stix2._register_type(_Custom, version="2.0") _register_type(_Custom, version="2.0")
return _Custom return _Custom
return custom_builder return custom_builder

View File

@ -4,11 +4,11 @@ from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..utils import NOW
from .common import ExternalReference, GranularMarking
from .properties import (BooleanProperty, IDProperty, IntegerProperty, from .properties import (BooleanProperty, IDProperty, IntegerProperty,
ListProperty, ReferenceProperty, StringProperty, ListProperty, ReferenceProperty, StringProperty,
TimestampProperty, TypeProperty) TimestampProperty, TypeProperty)
from ..utils import NOW
from .common import ExternalReference, GranularMarking
class STIXRelationshipObject(_STIXBase, _MarkingsMixin): class STIXRelationshipObject(_STIXBase, _MarkingsMixin):

View File

@ -1,9 +1,9 @@
from collections import OrderedDict from collections import OrderedDict
from stix2 import parse from ..base import _STIXBase
from stix2.base import _STIXBase from ..core import parse
from ..utils import _get_dict, get_class_hierarchy_names
from .properties import IDProperty, ListProperty, Property, TypeProperty from .properties import IDProperty, ListProperty, Property, TypeProperty
from stix2.utils import _get_dict, get_class_hierarchy_names
class STIXObjectProperty(Property): class STIXObjectProperty(Property):

View File

@ -4,11 +4,11 @@ from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from .properties import (BooleanProperty, DictionaryProperty, HashesProperty,
IDProperty, ListProperty, Property,
ReferenceProperty, SelectorProperty, StringProperty,
TimestampProperty, TypeProperty)
from ..utils import NOW, _get_dict from ..utils import NOW, _get_dict
from .properties import (BooleanProperty, DictionaryProperty, HashesProperty,
IDProperty, ListProperty, Property, ReferenceProperty,
SelectorProperty, StringProperty, TimestampProperty,
TypeProperty)
class ExternalReference(_STIXBase): class ExternalReference(_STIXBase):

View File

@ -12,12 +12,12 @@ import re
from ..base import _Extension, _Observable, _STIXBase from ..base import _Extension, _Observable, _STIXBase
from ..exceptions import (AtLeastOnePropertyError, CustomContentError, from ..exceptions import (AtLeastOnePropertyError, CustomContentError,
DependentPropertiesError, ParseError) DependentPropertiesError, ParseError)
from ..utils import TYPE_REGEX, _get_dict
from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty, from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, FloatProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty,
HashesProperty, HexProperty, IntegerProperty, HashesProperty, HexProperty, IntegerProperty,
ListProperty, ObjectReferenceProperty, Property, ListProperty, ObjectReferenceProperty, Property,
StringProperty, TimestampProperty, TypeProperty) StringProperty, TimestampProperty, TypeProperty)
from ..utils import TYPE_REGEX, _get_dict
class ObservableProperty(Property): class ObservableProperty(Property):

View File

@ -10,9 +10,9 @@ import uuid
from six import string_types, text_type from six import string_types, text_type
from stix2patterns.validator import run_validator from stix2patterns.validator import run_validator
from stix2.base import _STIXBase from ..base import _STIXBase
from stix2.exceptions import DictionaryKeyError from ..exceptions import DictionaryKeyError
from stix2.utils import _get_dict, parse_into_datetime from ..utils import _get_dict, parse_into_datetime
class Property(object): class Property(object):

View File

@ -3,18 +3,17 @@
from collections import OrderedDict from collections import OrderedDict
import re import re
import stix2
from ..base import _STIXBase from ..base import _STIXBase
from ..core import _register_type
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..utils import NOW, TYPE_REGEX
from .common import ExternalReference, GranularMarking, KillChainPhase
from .observables import ObservableProperty
from .properties import (BooleanProperty, DictionaryProperty, from .properties import (BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, FloatProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty,
IDProperty, IntegerProperty, ListProperty, IDProperty, IntegerProperty, ListProperty,
PatternProperty, ReferenceProperty, StringProperty, PatternProperty, ReferenceProperty, StringProperty,
TimestampProperty, TypeProperty) TimestampProperty, TypeProperty)
from ..utils import NOW, TYPE_REGEX
from .common import ExternalReference, GranularMarking, KillChainPhase
from .observables import ObservableProperty
class STIXDomainObject(_STIXBase, _MarkingsMixin): class STIXDomainObject(_STIXBase, _MarkingsMixin):
@ -585,7 +584,7 @@ def CustomObject(type='x-custom-type', properties=None):
return return
raise e raise e
stix2._register_type(_Custom, version="2.1") _register_type(_Custom, version="2.1")
return _Custom return _Custom
return custom_builder return custom_builder

View File

@ -4,11 +4,11 @@ from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..utils import NOW
from .common import ExternalReference, GranularMarking
from .properties import (BooleanProperty, IDProperty, IntegerProperty, from .properties import (BooleanProperty, IDProperty, IntegerProperty,
ListProperty, ReferenceProperty, StringProperty, ListProperty, ReferenceProperty, StringProperty,
TimestampProperty, TypeProperty) TimestampProperty, TypeProperty)
from ..utils import NOW
from .common import ExternalReference, GranularMarking
class STIXRelationshipObject(_STIXBase, _MarkingsMixin): class STIXRelationshipObject(_STIXBase, _MarkingsMixin):