Skip to content

Commit

Permalink
adding pretty to solve oasis-open#561
Browse files Browse the repository at this point in the history
  • Loading branch information
himynamesdave committed Oct 25, 2023
1 parent 2860699 commit 3df117f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stix2/datastore/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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:
Expand All @@ -611,15 +611,15 @@ 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)
if isinstance(parsed_data, _STIXBase):
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
Expand Down

0 comments on commit 3df117f

Please sign in to comment.