diff --git a/stix2/v20/bundle.py b/stix2/v20/bundle.py index 41da892..a945063 100644 --- a/stix2/v20/bundle.py +++ b/stix2/v20/bundle.py @@ -1,50 +1,8 @@ from collections import OrderedDict from ..base import _STIXBase -from ..core import parse -from ..utils import _get_dict, get_class_hierarchy_names -from .properties import (IDProperty, ListProperty, Property, StringProperty, - TypeProperty) - - -class STIXObjectProperty(Property): - - def __init__(self, allow_custom=False, *args, **kwargs): - self.allow_custom = allow_custom - super(STIXObjectProperty, self).__init__(*args, **kwargs) - - def clean(self, value): - # Any STIX Object (SDO, SRO, or Marking Definition) can be added to - # a bundle with no further checks. - if any(x in ('STIXDomainObject', 'STIXRelationshipObject', 'MarkingDefinition') - for x in get_class_hierarchy_names(value)): - # A simple "is this a spec version 2.1+ object" test. For now, - # limit 2.0 bundles to 2.0 objects. It's not possible yet to - # have validation co-constraints among properties, e.g. have - # validation here depend on the value of another property - # (spec_version). So this is a hack, and not technically spec- - # compliant. - if 'spec_version' in value: - raise ValueError("Spec version 2.0 bundles don't yet support " - "containing objects of a different spec " - "version.") - return value - try: - dictified = _get_dict(value) - except ValueError: - raise ValueError("This property may only contain a dictionary or object") - if dictified == {}: - raise ValueError("This property may only contain a non-empty dictionary or object") - if 'type' in dictified and dictified['type'] == 'bundle': - raise ValueError('This property may not contain a Bundle object') - if 'spec_version' in dictified: - # See above comment regarding spec_version. - raise ValueError("Spec version 2.0 bundles don't yet support " - "containing objects of a different spec version.") - - parsed_obj = parse(dictified, allow_custom=self.allow_custom) - - return parsed_obj +from ..properties import (IDProperty, ListProperty, STIXObjectProperty, + StringProperty, TypeProperty) class Bundle(_STIXBase): diff --git a/stix2/v21/bundle.py b/stix2/v21/bundle.py index 794b8a0..766e34a 100644 --- a/stix2/v21/bundle.py +++ b/stix2/v21/bundle.py @@ -1,48 +1,21 @@ from collections import OrderedDict from ..base import _STIXBase -from ..core import parse -from ..utils import _get_dict, get_class_hierarchy_names -from .properties import IDProperty, ListProperty, Property, TypeProperty - - -class STIXObjectProperty(Property): - - def __init__(self, allow_custom=False, *args, **kwargs): - self.allow_custom = allow_custom - super(STIXObjectProperty, self).__init__(*args, **kwargs) - - def clean(self, value): - # Any STIX Object (SDO, SRO, or Marking Definition) can be added to - # a bundle with no further checks. - if any(x in ('STIXDomainObject', 'STIXRelationshipObject', 'MarkingDefinition') - for x in get_class_hierarchy_names(value)): - return value - try: - dictified = _get_dict(value) - except ValueError: - raise ValueError("This property may only contain a dictionary or object") - if dictified == {}: - raise ValueError("This property may only contain a non-empty dictionary or object") - if 'type' in dictified and dictified['type'] == 'bundle': - raise ValueError('This property may not contain a Bundle object') - - parsed_obj = parse(dictified, allow_custom=self.allow_custom) - - return parsed_obj +from ..properties import (IDProperty, ListProperty, STIXObjectProperty, + TypeProperty) class Bundle(_STIXBase): + # TODO: Add link """For more detailed information on this object's properties, see - TODO: Update this to a STIX 2.1 link. - `the STIX 2.0 specification `__. + `the STIX 2.1 specification `__. """ _type = 'bundle' _properties = OrderedDict([ ('type', TypeProperty(_type)), ('id', IDProperty(_type)), - ('objects', ListProperty(STIXObjectProperty)), + ('objects', ListProperty(STIXObjectProperty(spec_version='2.1'))), ]) def __init__(self, *args, **kwargs):