diff --git a/stix2/datastore/memory.py b/stix2/datastore/memory.py index e833c57..bc7c385 100644 --- a/stix2/datastore/memory.py +++ b/stix2/datastore/memory.py @@ -211,16 +211,20 @@ class MemorySink(DataSink): else: bundle = v20.Bundle(all_objs, allow_custom=self.allow_custom) - if not os.path.exists(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) + if path.endswith(".json"): + if not os.path.exists(os.path.dirname(path)): + os.makedirs(os.path.dirname(path)) + else: + if not os.path.exists(path): + os.makedirs(path) - # if the user only provided a directory, use the bundle id for filename - if os.path.isdir(path): + # if the user only provided a directory, use the bundle id for filename path = os.path.join(path, bundle["id"] + ".json") with io.open(path, "w", encoding=encoding) as f: bundle = bundle.serialize(pretty=True, encoding=encoding, ensure_ascii=False) f.write(bundle) + return path save_to_file.__doc__ = MemoryStore.save_to_file.__doc__ diff --git a/stix2/test/v20/test_datastore.py b/stix2/test/v20/test_datastore.py index 606e5b0..f783d4c 100644 --- a/stix2/test/v20/test_datastore.py +++ b/stix2/test/v20/test_datastore.py @@ -4,7 +4,7 @@ from stix2.datastore import ( CompositeDataSource, DataSink, DataSource, DataStoreMixin, ) from stix2.datastore.filters import Filter -from stix2.test.v20.constants import CAMPAIGN_MORE_KWARGS +from .constants import CAMPAIGN_MORE_KWARGS def test_datasource_abstract_class_raises_error(): diff --git a/stix2/test/v20/test_datastore_filesystem.py b/stix2/test/v20/test_datastore_filesystem.py index 47a4eec..906be52 100644 --- a/stix2/test/v20/test_datastore_filesystem.py +++ b/stix2/test/v20/test_datastore_filesystem.py @@ -5,7 +5,7 @@ import shutil import pytest import stix2 -from stix2.test.v20.constants import ( +from .constants import ( CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID, INDICATOR_KWARGS, MALWARE_ID, MALWARE_KWARGS, RELATIONSHIP_IDS, ) diff --git a/stix2/test/v21/test_datastore.py b/stix2/test/v21/test_datastore.py index 8a4bcdb..f783d4c 100644 --- a/stix2/test/v21/test_datastore.py +++ b/stix2/test/v21/test_datastore.py @@ -4,7 +4,7 @@ from stix2.datastore import ( CompositeDataSource, DataSink, DataSource, DataStoreMixin, ) from stix2.datastore.filters import Filter -from stix2.test.v21.constants import CAMPAIGN_MORE_KWARGS +from .constants import CAMPAIGN_MORE_KWARGS def test_datasource_abstract_class_raises_error(): diff --git a/stix2/test/v21/test_datastore_filesystem.py b/stix2/test/v21/test_datastore_filesystem.py index 6954eb1..1af21b4 100644 --- a/stix2/test/v21/test_datastore_filesystem.py +++ b/stix2/test/v21/test_datastore_filesystem.py @@ -5,7 +5,7 @@ import shutil import pytest import stix2 -from stix2.test.v21.constants import ( +from .constants import ( CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID, INDICATOR_KWARGS, MALWARE_ID, MALWARE_KWARGS, RELATIONSHIP_IDS, )