Hide builder methods in 'custom.py' and update imports accordingly

stix2.1
Emmanuelle Vargas-Gonzalez 2018-07-11 08:11:47 -04:00
parent 6bd797e258
commit e513c8d638
7 changed files with 18 additions and 18 deletions

View File

@ -7,7 +7,7 @@ from .core import (_register_object, _register_marking, _register_observable,
from .utils import TYPE_REGEX, get_class_hierarchy_names from .utils import TYPE_REGEX, get_class_hierarchy_names
def custom_object_builder(cls, type, properties, version): def _custom_object_builder(cls, type, properties, version):
class _CustomObject(cls, STIXDomainObject): class _CustomObject(cls, STIXDomainObject):
if not re.match(TYPE_REGEX, type): if not re.match(TYPE_REGEX, type):
@ -38,7 +38,7 @@ def custom_object_builder(cls, type, properties, version):
return _CustomObject return _CustomObject
def custom_marking_builder(cls, type, properties, version): def _custom_marking_builder(cls, type, properties, version):
class _CustomMarking(cls, _STIXBase): class _CustomMarking(cls, _STIXBase):
if not properties or not isinstance(properties, list): if not properties or not isinstance(properties, list):
@ -62,7 +62,7 @@ def custom_marking_builder(cls, type, properties, version):
return _CustomMarking return _CustomMarking
def custom_observable_builder(cls, type, properties, version): def _custom_observable_builder(cls, type, properties, version):
class _CustomObservable(cls, _Observable): class _CustomObservable(cls, _Observable):
if not re.match(TYPE_REGEX, type): if not re.match(TYPE_REGEX, type):
@ -102,7 +102,7 @@ def custom_observable_builder(cls, type, properties, version):
return _CustomObservable return _CustomObservable
def custom_extension_builder(cls, observable, type, properties, version): def _custom_extension_builder(cls, observable, type, properties, version):
if not observable or not issubclass(observable, _Observable): if not observable or not issubclass(observable, _Observable):
raise ValueError("'observable' must be a valid Observable class!") raise ValueError("'observable' must be a valid Observable class!")

View File

@ -3,7 +3,7 @@
from collections import OrderedDict from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..custom import custom_marking_builder from ..custom import _custom_marking_builder
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..properties import (HashesProperty, IDProperty, ListProperty, Property, from ..properties import (HashesProperty, IDProperty, ListProperty, Property,
ReferenceProperty, SelectorProperty, StringProperty, ReferenceProperty, SelectorProperty, StringProperty,
@ -147,7 +147,7 @@ def CustomMarking(type='x-custom-marking', properties=None):
""" """
def wrapper(cls): def wrapper(cls):
return custom_marking_builder(cls, type, properties, '2.0') return _custom_marking_builder(cls, type, properties, '2.0')
return wrapper return wrapper

View File

@ -9,7 +9,7 @@ from collections import OrderedDict
import itertools import itertools
from ..base import _Extension, _Observable, _STIXBase from ..base import _Extension, _Observable, _STIXBase
from ..custom import custom_extension_builder, custom_observable_builder from ..custom import _custom_extension_builder, _custom_observable_builder
from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError
from ..properties import (BinaryProperty, BooleanProperty, DictionaryProperty, from ..properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, EmbeddedObjectProperty, EnumProperty,
@ -784,7 +784,7 @@ def CustomObservable(type='x-custom-observable', properties=None):
properties, properties,
[('extensions', ExtensionsProperty(enclosing_type=type))] [('extensions', ExtensionsProperty(enclosing_type=type))]
])) ]))
return custom_observable_builder(cls, type, _properties, '2.0') return _custom_observable_builder(cls, type, _properties, '2.0')
return wrapper return wrapper
@ -792,5 +792,5 @@ def CustomExtension(observable=None, type='x-custom-observable-ext', properties=
"""Decorator for custom extensions to STIX Cyber Observables. """Decorator for custom extensions to STIX Cyber Observables.
""" """
def wrapper(cls): def wrapper(cls):
return custom_extension_builder(cls, observable, type, properties, '2.0') return _custom_extension_builder(cls, observable, type, properties, '2.0')
return wrapper return wrapper

View File

@ -5,7 +5,7 @@ from collections import OrderedDict
import itertools import itertools
from ..core import STIXDomainObject from ..core import STIXDomainObject
from ..custom import custom_object_builder from ..custom import _custom_object_builder
from ..properties import (BooleanProperty, IDProperty, IntegerProperty, from ..properties import (BooleanProperty, IDProperty, IntegerProperty,
ListProperty, ObservableProperty, PatternProperty, ListProperty, ObservableProperty, PatternProperty,
ReferenceProperty, StringProperty, TimestampProperty, ReferenceProperty, StringProperty, TimestampProperty,
@ -366,6 +366,6 @@ def CustomObject(type='x-custom-type', properties=None):
], ],
sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0]) sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0])
])) ]))
return custom_object_builder(cls, type, _properties, '2.0') return _custom_object_builder(cls, type, _properties, '2.0')
return wrapper return wrapper

View File

@ -3,7 +3,7 @@
from collections import OrderedDict from collections import OrderedDict
from ..base import _STIXBase from ..base import _STIXBase
from ..custom import custom_marking_builder from ..custom import _custom_marking_builder
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..properties import (BooleanProperty, DictionaryProperty, HashesProperty, from ..properties import (BooleanProperty, DictionaryProperty, HashesProperty,
IDProperty, ListProperty, Property, IDProperty, ListProperty, Property,
@ -186,7 +186,7 @@ def CustomMarking(type='x-custom-marking', properties=None):
""" """
def wrapper(cls): def wrapper(cls):
return custom_marking_builder(cls, type, properties, '2.1') return _custom_marking_builder(cls, type, properties, '2.1')
return wrapper return wrapper

View File

@ -9,7 +9,7 @@ from collections import OrderedDict
import itertools import itertools
from ..base import _Extension, _Observable, _STIXBase from ..base import _Extension, _Observable, _STIXBase
from ..custom import custom_extension_builder, custom_observable_builder from ..custom import _custom_extension_builder, _custom_observable_builder
from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError
from ..properties import (BinaryProperty, BooleanProperty, DictionaryProperty, from ..properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, EmbeddedObjectProperty, EnumProperty,
@ -820,7 +820,7 @@ def CustomObservable(type='x-custom-observable', properties=None):
properties, properties,
[('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=type))] [('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=type))]
])) ]))
return custom_observable_builder(cls, type, _properties, '2.1') return _custom_observable_builder(cls, type, _properties, '2.1')
return wrapper return wrapper
@ -828,5 +828,5 @@ def CustomExtension(observable=None, type='x-custom-observable-ext', properties=
"""Decorator for custom extensions to STIX Cyber Observables. """Decorator for custom extensions to STIX Cyber Observables.
""" """
def wrapper(cls): def wrapper(cls):
return custom_extension_builder(cls, observable, type, properties, '2.1') return _custom_extension_builder(cls, observable, type, properties, '2.1')
return wrapper return wrapper

View File

@ -5,7 +5,7 @@ import itertools
from ..base import _STIXBase from ..base import _STIXBase
from ..core import STIXDomainObject from ..core import STIXDomainObject
from ..custom import custom_object_builder from ..custom import _custom_object_builder
from ..properties import (BooleanProperty, DictionaryProperty, from ..properties import (BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, FloatProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty,
IDProperty, IntegerProperty, ListProperty, IDProperty, IntegerProperty, ListProperty,
@ -550,6 +550,6 @@ def CustomObject(type='x-custom-type', properties=None):
], ],
sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0]) sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0])
])) ]))
return custom_object_builder(cls, type, _properties, '2.1') return _custom_object_builder(cls, type, _properties, '2.1')
return wrapper return wrapper