Added adaptability to the workbench module, regarding the

autogenerated docstrings: v20/v21 is automatically referenced as
appropriate, based on stix2.DEFAULT_VERSION.  To avoid
duplication, I also moved _STIX_VID from test_workbench.py to
workbench.py; the former now imports it from the latter.
master
Michael Chisholm 2019-07-24 17:20:52 -04:00
parent 22face6c1a
commit b0eb518997
2 changed files with 11 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import os
import stix2 import stix2
from stix2.workbench import ( from stix2.workbench import (
AttackPattern, Campaign, CourseOfAction, ExternalReference, _STIX_VID, AttackPattern, Campaign, CourseOfAction, ExternalReference,
FileSystemSource, Filter, Identity, Indicator, IntrusionSet, Malware, FileSystemSource, Filter, Identity, Indicator, IntrusionSet, Malware,
MarkingDefinition, ObservedData, Relationship, Report, StatementMarking, MarkingDefinition, ObservedData, Relationship, Report, StatementMarking,
ThreatActor, Tool, Vulnerability, add_data_source, all_versions, ThreatActor, Tool, Vulnerability, add_data_source, all_versions,
@ -14,7 +14,6 @@ from stix2.workbench import (
) )
# Auto-detect some settings based on the current default STIX version # Auto-detect some settings based on the current default STIX version
_STIX_VID = "v" + stix2.DEFAULT_VERSION.replace(".", "")
_STIX_DATA_PATH = os.path.join( _STIX_DATA_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), os.path.dirname(os.path.realpath(__file__)),
_STIX_VID, _STIX_VID,

View File

@ -53,6 +53,11 @@ from . import ( # noqa: F401
) )
from .datastore.filters import FilterSet from .datastore.filters import FilterSet
# Enable some adaptation to the current default supported STIX version.
_STIX_VID = "v" + stix2.DEFAULT_VERSION.replace(".", "")
# Use an implicit MemoryStore # Use an implicit MemoryStore
_environ = Environment(store=MemoryStore()) _environ = Environment(store=MemoryStore())
@ -133,7 +138,11 @@ def _setup_workbench():
# have undesirable side-effects, but actually it seems to work. # have undesirable side-effects, but actually it seems to work.
# So far... # So far...
new_class_dict = { new_class_dict = {
'__doc__': 'Workbench wrapper around the `{0} <stix2.v20.sdo.rst#stix2.v20.sdo.{0}>`__ object. {1}'.format(obj_type.__name__, STIX_OBJ_DOCS), '__doc__': 'Workbench wrapper around the `{0} <stix2.{1}.sdo.rst#stix2.{1}.sdo.{0}>`__ object. {2}'.format(
obj_type.__name__,
_STIX_VID,
STIX_OBJ_DOCS,
),
'created_by': _created_by_wrapper, 'created_by': _created_by_wrapper,
'relationships': _relationships_wrapper, 'relationships': _relationships_wrapper,
'related': _related_wrapper, 'related': _related_wrapper,