From 7f9a3c49ea3076f37ea56a940c47068050d0c155 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Thu, 15 Mar 2018 13:51:47 -0400 Subject: [PATCH] Update TAXIICollectionSink.add() to use serialize(). Call parse() on dict objects. Pass UTF-8 strings to taxii2client. closes #134 --- stix2/datastore/taxii.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stix2/datastore/taxii.py b/stix2/datastore/taxii.py index 5af4354..ee3af35 100644 --- a/stix2/datastore/taxii.py +++ b/stix2/datastore/taxii.py @@ -67,14 +67,17 @@ class TAXIICollectionSink(DataSink): """ if isinstance(stix_data, _STIXBase): # adding python STIX object - bundle = dict(Bundle(stix_data, allow_custom=self.allow_custom)) + if stix_data["type"] == "bundle": + bundle = stix_data.serialize(encoding="utf-8") + else: + bundle = Bundle(stix_data, allow_custom=self.allow_custom).serialize(encoding="utf-8") elif isinstance(stix_data, dict): # adding python dict (of either Bundle or STIX obj) if stix_data["type"] == "bundle": - bundle = stix_data + bundle = parse(stix_data, allow_custom=self.allow_custom, version=version).serialize(encoding="utf-8") else: - bundle = dict(Bundle(stix_data, allow_custom=self.allow_custom)) + bundle = Bundle(stix_data, allow_custom=self.allow_custom).serialize(encoding="utf-8") elif isinstance(stix_data, list): # adding list of something - recurse on each @@ -85,9 +88,9 @@ class TAXIICollectionSink(DataSink): # adding json encoded string of STIX content stix_data = parse(stix_data, allow_custom=self.allow_custom, version=version) if stix_data["type"] == "bundle": - bundle = dict(stix_data) + bundle = stix_data.serialize(encoding="utf-8") else: - bundle = dict(Bundle(stix_data, allow_custom=self.allow_custom)) + bundle = Bundle(stix_data, allow_custom=self.allow_custom).serialize(encoding="utf-8") else: raise TypeError("stix_data must be as STIX object(or list of),json formatted STIX (or list of), or a json formatted STIX bundle")