From 50df6f14744697fdbdbad04bebf8516e4c09aea3 Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Fri, 27 Mar 2020 05:53:39 -0400 Subject: [PATCH] Rename core.py -> parsing.py --- stix2/__init__.py | 2 +- stix2/custom.py | 2 +- stix2/datastore/filesystem.py | 2 +- stix2/datastore/memory.py | 2 +- stix2/datastore/taxii.py | 2 +- stix2/environment.py | 2 +- stix2/{core.py => parsing.py} | 0 stix2/properties.py | 2 +- stix2/test/test_spec_version_detect.py | 2 +- stix2/test/v20/test_core.py | 32 +++++++++++++------------- stix2/test/v20/test_custom.py | 2 +- stix2/test/v21/test_core.py | 32 +++++++++++++------------- stix2/test/v21/test_custom.py | 2 +- 13 files changed, 42 insertions(+), 42 deletions(-) rename stix2/{core.py => parsing.py} (100%) diff --git a/stix2/__init__.py b/stix2/__init__.py index c9384a0..f3e02b4 100644 --- a/stix2/__init__.py +++ b/stix2/__init__.py @@ -23,7 +23,6 @@ DEFAULT_VERSION = '2.0' # Default version will always be the latest STIX 2.X version from .confidence import scales -from .core import _collect_stix2_mappings, parse, parse_observable from .datastore import CompositeDataSource from .datastore.filesystem import ( FileSystemSink, FileSystemSource, FileSystemStore, @@ -38,6 +37,7 @@ from .markings import ( add_markings, clear_markings, get_markings, is_marked, remove_markings, set_markings, ) +from .parsing import _collect_stix2_mappings, parse, parse_observable from .patterns import ( AndBooleanExpression, AndObservationExpression, BasicObjectPathComponent, BinaryConstant, BooleanConstant, EqualityComparisonExpression, diff --git a/stix2/custom.py b/stix2/custom.py index 687618d..6d1abc5 100644 --- a/stix2/custom.py +++ b/stix2/custom.py @@ -4,7 +4,7 @@ import re import six from .base import _cls_init -from .core import ( +from .parsing import ( _register_marking, _register_object, _register_observable, _register_observable_extension, ) diff --git a/stix2/datastore/filesystem.py b/stix2/datastore/filesystem.py index d5acc24..5a5844a 100644 --- a/stix2/datastore/filesystem.py +++ b/stix2/datastore/filesystem.py @@ -10,11 +10,11 @@ import six from stix2 import v20, v21 from stix2.base import _STIXBase -from stix2.core import parse from stix2.datastore import ( DataSink, DataSource, DataSourceError, DataStoreMixin, ) from stix2.datastore.filters import Filter, FilterSet, apply_common_filters +from stix2.parsing import parse from stix2.utils import format_datetime, get_type_from_id diff --git a/stix2/datastore/memory.py b/stix2/datastore/memory.py index 52da168..f71b763 100644 --- a/stix2/datastore/memory.py +++ b/stix2/datastore/memory.py @@ -7,9 +7,9 @@ import os from stix2 import v20, v21 from stix2.base import _STIXBase -from stix2.core import parse from stix2.datastore import DataSink, DataSource, DataStoreMixin from stix2.datastore.filters import FilterSet, apply_common_filters +from stix2.parsing import parse def _add(store, stix_data, allow_custom=True, version=None): diff --git a/stix2/datastore/taxii.py b/stix2/datastore/taxii.py index 41c968f..58dcdbc 100644 --- a/stix2/datastore/taxii.py +++ b/stix2/datastore/taxii.py @@ -4,11 +4,11 @@ from requests.exceptions import HTTPError from stix2 import v20, v21 from stix2.base import _STIXBase -from stix2.core import parse from stix2.datastore import ( DataSink, DataSource, DataSourceError, DataStoreMixin, ) from stix2.datastore.filters import Filter, FilterSet, apply_common_filters +from stix2.parsing import parse from stix2.utils import deduplicate try: diff --git a/stix2/environment.py b/stix2/environment.py index ada5f33..6e3c76a 100644 --- a/stix2/environment.py +++ b/stix2/environment.py @@ -4,8 +4,8 @@ import copy import logging import time -from .core import parse as _parse from .datastore import CompositeDataSource, DataStoreMixin +from .parsing import parse as _parse from .utils import STIXdatetime, parse_into_datetime logger = logging.getLogger(__name__) diff --git a/stix2/core.py b/stix2/parsing.py similarity index 100% rename from stix2/core.py rename to stix2/parsing.py diff --git a/stix2/properties.py b/stix2/properties.py index e02f96b..be66533 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -12,11 +12,11 @@ from six import string_types, text_type import stix2 from .base import _STIXBase -from .core import STIX2_OBJ_MAPS, parse, parse_observable from .exceptions import ( CustomContentError, DictionaryKeyError, MissingPropertiesError, MutuallyExclusivePropertiesError, ) +from .parsing import STIX2_OBJ_MAPS, parse, parse_observable from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime try: diff --git a/stix2/test/test_spec_version_detect.py b/stix2/test/test_spec_version_detect.py index d2a9da8..7039024 100644 --- a/stix2/test/test_spec_version_detect.py +++ b/stix2/test/test_spec_version_detect.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import pytest -from stix2.core import _detect_spec_version +from stix2.parsing import _detect_spec_version @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_core.py b/stix2/test/v20/test_core.py index d2efa22..ca701fb 100644 --- a/stix2/test/v20/test_core.py +++ b/stix2/test/v20/test_core.py @@ -1,7 +1,7 @@ import pytest import stix2 -from stix2 import core, exceptions +from stix2 import exceptions, parsing from .constants import IDENTITY_ID @@ -46,14 +46,14 @@ BUNDLE = { def test_dict_to_stix2_bundle_with_version(): with pytest.raises(exceptions.ExtraPropertiesError) as excinfo: - core.dict_to_stix2(BUNDLE, version='2.1') + parsing.dict_to_stix2(BUNDLE, version='2.1') assert str(excinfo.value) == "Unexpected properties for Bundle: (spec_version)." def test_parse_observable_with_version(): observable = {"type": "file", "name": "foo.exe"} - obs_obj = core.parse_observable(observable, version='2.0') + obs_obj = parsing.parse_observable(observable, version='2.0') v = 'v20' assert v in str(obs_obj.__class__) @@ -62,38 +62,38 @@ def test_parse_observable_with_version(): @pytest.mark.xfail(reason="The default version is no longer 2.0", condition=stix2.DEFAULT_VERSION != "2.0") def test_parse_observable_with_no_version(): observable = {"type": "file", "name": "foo.exe"} - obs_obj = core.parse_observable(observable) + obs_obj = parsing.parse_observable(observable) v = 'v20' assert v in str(obs_obj.__class__) def test_register_object_with_version(): - bundle = core.dict_to_stix2(BUNDLE, version='2.0') - core._register_object(bundle.objects[0].__class__, version='2.0') + bundle = parsing.dict_to_stix2(BUNDLE, version='2.0') + parsing._register_object(bundle.objects[0].__class__, version='2.0') v = 'v20' - assert bundle.objects[0].type in core.STIX2_OBJ_MAPS[v]['objects'] + assert bundle.objects[0].type in parsing.STIX2_OBJ_MAPS[v]['objects'] # spec_version is not in STIX 2.0, and is required in 2.1, so this # suffices as a test for a STIX 2.0 object. assert "spec_version" not in bundle.objects[0] def test_register_marking_with_version(): - core._register_marking(stix2.v20.TLP_WHITE.__class__, version='2.0') + parsing._register_marking(stix2.v20.TLP_WHITE.__class__, version='2.0') v = 'v20' - assert stix2.v20.TLP_WHITE.definition._type in core.STIX2_OBJ_MAPS[v]['markings'] + assert stix2.v20.TLP_WHITE.definition._type in parsing.STIX2_OBJ_MAPS[v]['markings'] assert v in str(stix2.v20.TLP_WHITE.__class__) @pytest.mark.xfail(reason="The default version is no longer 2.0", condition=stix2.DEFAULT_VERSION != "2.0") def test_register_marking_with_no_version(): # Uses default version (2.0 in this case) - core._register_marking(stix2.v20.TLP_WHITE.__class__) + parsing._register_marking(stix2.v20.TLP_WHITE.__class__) v = 'v20' - assert stix2.v20.TLP_WHITE.definition._type in core.STIX2_OBJ_MAPS[v]['markings'] + assert stix2.v20.TLP_WHITE.definition._type in parsing.STIX2_OBJ_MAPS[v]['markings'] assert v in str(stix2.v20.TLP_WHITE.__class__) @@ -128,10 +128,10 @@ def test_register_observable_with_version(): }, }, ) - core._register_observable(observed_data.objects['0'].__class__, version='2.0') + parsing._register_observable(observed_data.objects['0'].__class__, version='2.0') v = 'v20' - assert observed_data.objects['0'].type in core.STIX2_OBJ_MAPS[v]['observables'] + assert observed_data.objects['0'].type in parsing.STIX2_OBJ_MAPS[v]['observables'] assert v in str(observed_data.objects['0'].__class__) @@ -166,11 +166,11 @@ def test_register_observable_extension_with_version(): }, }, ) - core._register_observable_extension(observed_data.objects['0'], observed_data.objects['0'].extensions['ntfs-ext'].__class__, version='2.0') + parsing._register_observable_extension(observed_data.objects['0'], observed_data.objects['0'].extensions['ntfs-ext'].__class__, version='2.0') v = 'v20' - assert observed_data.objects['0'].type in core.STIX2_OBJ_MAPS[v]['observables'] + assert observed_data.objects['0'].type in parsing.STIX2_OBJ_MAPS[v]['observables'] assert v in str(observed_data.objects['0'].__class__) - assert observed_data.objects['0'].extensions['ntfs-ext']._type in core.STIX2_OBJ_MAPS[v]['observable-extensions']['file'] + assert observed_data.objects['0'].extensions['ntfs-ext']._type in parsing.STIX2_OBJ_MAPS[v]['observable-extensions']['file'] assert v in str(observed_data.objects['0'].extensions['ntfs-ext'].__class__) diff --git a/stix2/test/v20/test_custom.py b/stix2/test/v20/test_custom.py index b986777..e24393c 100644 --- a/stix2/test/v20/test_custom.py +++ b/stix2/test/v20/test_custom.py @@ -967,7 +967,7 @@ def test_register_custom_object(): class CustomObject2(object): _type = 'awesome-object' - stix2.core._register_object(CustomObject2, version="2.0") + stix2.parsing._register_object(CustomObject2, version="2.0") # Note that we will always check against newest OBJ_MAP. assert (CustomObject2._type, CustomObject2) in stix2.v20.OBJ_MAP.items() diff --git a/stix2/test/v21/test_core.py b/stix2/test/v21/test_core.py index 2018395..48f0055 100644 --- a/stix2/test/v21/test_core.py +++ b/stix2/test/v21/test_core.py @@ -1,7 +1,7 @@ import pytest import stix2 -from stix2 import core, exceptions +from stix2 import exceptions, parsing from .constants import IDENTITY_ID, OBSERVED_DATA_ID @@ -50,7 +50,7 @@ BUNDLE = { def test_dict_to_stix2_bundle_with_version(): with pytest.raises(exceptions.InvalidValueError) as excinfo: - core.dict_to_stix2(BUNDLE, version='2.0') + parsing.dict_to_stix2(BUNDLE, version='2.0') msg = "Invalid value for Bundle 'objects': Spec version 2.0 bundles don't yet support containing objects of a different spec version." assert str(excinfo.value) == msg @@ -58,7 +58,7 @@ def test_dict_to_stix2_bundle_with_version(): def test_parse_observable_with_version(): observable = {"type": "file", "name": "foo.exe"} - obs_obj = core.parse_observable(observable, version='2.1') + obs_obj = parsing.parse_observable(observable, version='2.1') v = 'v21' assert v in str(obs_obj.__class__) @@ -67,36 +67,36 @@ def test_parse_observable_with_version(): @pytest.mark.xfail(reason="The default version is not 2.1", condition=stix2.DEFAULT_VERSION != "2.1") def test_parse_observable_with_no_version(): observable = {"type": "file", "name": "foo.exe"} - obs_obj = core.parse_observable(observable) + obs_obj = parsing.parse_observable(observable) v = 'v21' assert v in str(obs_obj.__class__) def test_register_object_with_version(): - bundle = core.dict_to_stix2(BUNDLE, version='2.1') - core._register_object(bundle.objects[0].__class__) + bundle = parsing.dict_to_stix2(BUNDLE, version='2.1') + parsing._register_object(bundle.objects[0].__class__) v = 'v21' - assert bundle.objects[0].type in core.STIX2_OBJ_MAPS[v]['objects'] + assert bundle.objects[0].type in parsing.STIX2_OBJ_MAPS[v]['objects'] assert bundle.objects[0].spec_version == "2.1" def test_register_marking_with_version(): - core._register_marking(stix2.v21.TLP_WHITE.__class__, version='2.1') + parsing._register_marking(stix2.v21.TLP_WHITE.__class__, version='2.1') v = 'v21' - assert stix2.v21.TLP_WHITE.definition._type in core.STIX2_OBJ_MAPS[v]['markings'] + assert stix2.v21.TLP_WHITE.definition._type in parsing.STIX2_OBJ_MAPS[v]['markings'] assert v in str(stix2.v21.TLP_WHITE.__class__) @pytest.mark.xfail(reason="The default version is not 2.1", condition=stix2.DEFAULT_VERSION != "2.1") def test_register_marking_with_no_version(): # Uses default version (2.0 in this case) - core._register_marking(stix2.v21.TLP_WHITE.__class__) + parsing._register_marking(stix2.v21.TLP_WHITE.__class__) v = 'v21' - assert stix2.v21.TLP_WHITE.definition._type in core.STIX2_OBJ_MAPS[v]['markings'] + assert stix2.v21.TLP_WHITE.definition._type in parsing.STIX2_OBJ_MAPS[v]['markings'] assert v in str(stix2.v21.TLP_WHITE.__class__) @@ -131,10 +131,10 @@ def test_register_observable_with_default_version(): }, }, ) - core._register_observable(observed_data.objects['0'].__class__) + parsing._register_observable(observed_data.objects['0'].__class__) v = 'v21' - assert observed_data.objects['0'].type in core.STIX2_OBJ_MAPS[v]['observables'] + assert observed_data.objects['0'].type in parsing.STIX2_OBJ_MAPS[v]['observables'] assert v in str(observed_data.objects['0'].__class__) @@ -169,11 +169,11 @@ def test_register_observable_extension_with_default_version(): }, }, ) - core._register_observable_extension(observed_data.objects['0'], observed_data.objects['0'].extensions['ntfs-ext'].__class__) + parsing._register_observable_extension(observed_data.objects['0'], observed_data.objects['0'].extensions['ntfs-ext'].__class__) v = 'v21' - assert observed_data.objects['0'].type in core.STIX2_OBJ_MAPS[v]['observables'] + assert observed_data.objects['0'].type in parsing.STIX2_OBJ_MAPS[v]['observables'] assert v in str(observed_data.objects['0'].__class__) - assert observed_data.objects['0'].extensions['ntfs-ext']._type in core.STIX2_OBJ_MAPS[v]['observable-extensions']['file'] + assert observed_data.objects['0'].extensions['ntfs-ext']._type in parsing.STIX2_OBJ_MAPS[v]['observable-extensions']['file'] assert v in str(observed_data.objects['0'].extensions['ntfs-ext'].__class__) diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index ef57a9b..a9969b8 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -1186,7 +1186,7 @@ def test_register_custom_object(): class CustomObject2(object): _type = 'awesome-object' - stix2.core._register_object(CustomObject2, version="2.1") + stix2.parsing._register_object(CustomObject2, version="2.1") # Note that we will always check against newest OBJ_MAP. assert (CustomObject2._type, CustomObject2) in stix2.v21.OBJ_MAP.items()