From 131ab5643beeab6b6c443c6e3a17e29e57928624 Mon Sep 17 00:00:00 2001 From: Shanthanu S Rai <31900229+shanthanu9@users.noreply.github.com> Date: Sun, 13 Nov 2022 10:32:58 +0530 Subject: [PATCH] Add pretty keywork argument for filesystem --- stix2/datastore/filesystem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stix2/datastore/filesystem.py b/stix2/datastore/filesystem.py index 2209116a..c48306e7 100644 --- a/stix2/datastore/filesystem.py +++ b/stix2/datastore/filesystem.py @@ -554,7 +554,7 @@ def __init__(self, stix_dir, allow_custom=False, bundlify=False): def stix_dir(self): return self._stix_dir - def _check_path_and_write(self, stix_obj, encoding='utf-8'): + def _check_path_and_write(self, stix_obj, encoding='utf-8', pretty=True): """Write the given STIX object to a file in the STIX file directory. """ type_dir = os.path.join(self._stix_dir, stix_obj["type"]) @@ -585,9 +585,9 @@ def _check_path_and_write(self, stix_obj, encoding='utf-8'): raise DataSourceError("Attempted to overwrite file (!) at: {}".format(file_path)) with io.open(file_path, mode='w', encoding=encoding) as f: - fp_serialize(stix_obj, f, pretty=True, encoding=encoding, ensure_ascii=False) + fp_serialize(stix_obj, f, pretty=pretty, encoding=encoding, ensure_ascii=False) - def add(self, stix_data=None, version=None): + def add(self, stix_data=None, version=None, pretty=True): """Add STIX objects to file directory. Args: @@ -611,7 +611,7 @@ def add(self, stix_data=None, version=None): elif isinstance(stix_data, _STIXBase): # adding python STIX object - self._check_path_and_write(stix_data) + self._check_path_and_write(stix_data, pretty=pretty) elif isinstance(stix_data, (str, dict)): parsed_data = parse(stix_data, allow_custom=self.allow_custom, version=version) @@ -619,7 +619,7 @@ def add(self, stix_data=None, version=None): self.add(parsed_data, version=version) else: # custom unregistered object type - self._check_path_and_write(parsed_data) + self._check_path_and_write(parsed_data, pretty=pretty) elif isinstance(stix_data, list): # recursively add individual STIX objects