Fix workbench wrapped classes for `parse()`.
The wrapped classes need to be in the OBJ_MAP mapping, not just the workbench.py globals.stix2.0
parent
b9bbd03481
commit
98cc86eef6
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import stix2
|
||||||
from . import AttackPattern as _AttackPattern
|
from . import AttackPattern as _AttackPattern
|
||||||
from . import Campaign as _Campaign
|
from . import Campaign as _Campaign
|
||||||
from . import CourseOfAction as _CourseOfAction
|
from . import CourseOfAction as _CourseOfAction
|
||||||
|
@ -121,22 +122,30 @@ def _constructor_wrapper(obj_type):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_constructor(cls, *args, **kwargs):
|
def new_constructor(cls, *args, **kwargs):
|
||||||
return _environ.create(wrapped_type, *args, **kwargs)
|
x = _environ.create(wrapped_type, *args, **kwargs)
|
||||||
|
return x
|
||||||
return new_constructor
|
return new_constructor
|
||||||
|
|
||||||
|
|
||||||
# Create wrapper classes whose constructors call the implicit environment's create()
|
def _setup_workbench():
|
||||||
for obj_type in STIX_OBJS:
|
# Create wrapper classes whose constructors call the implicit environment's create()
|
||||||
|
for obj_type in STIX_OBJS:
|
||||||
new_class_dict = {
|
new_class_dict = {
|
||||||
'__new__': _constructor_wrapper(obj_type),
|
'__new__': _constructor_wrapper(obj_type),
|
||||||
'__doc__': 'Workbench wrapper around the `{0} <stix2.v20.sdo.html#stix2.v20.sdo.{0}>`__. object. {1}'.format(obj_type.__name__, STIX_OBJ_DOCS)
|
'__doc__': 'Workbench wrapper around the `{0} <stix2.v20.sdo.html#stix2.v20.sdo.{0}>`__. object. {1}'.format(obj_type.__name__, STIX_OBJ_DOCS)
|
||||||
}
|
}
|
||||||
new_class = type(obj_type.__name__, (), new_class_dict)
|
new_class = type(obj_type.__name__, (), new_class_dict)
|
||||||
|
|
||||||
|
# Add our new class to this module's globals and to the library-wide mapping.
|
||||||
|
# This allows parse() to use the wrapped classes.
|
||||||
globals()[obj_type.__name__] = new_class
|
globals()[obj_type.__name__] = new_class
|
||||||
|
stix2.OBJ_MAP[obj_type._type] = new_class
|
||||||
new_class = None
|
new_class = None
|
||||||
|
|
||||||
|
|
||||||
|
_setup_workbench()
|
||||||
|
|
||||||
|
|
||||||
# Functions to get all objects of a specific type
|
# Functions to get all objects of a specific type
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue