From d828e41c78932aaf290371d95281021af10bfdae Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Wed, 11 Sep 2019 10:44:14 -0400 Subject: [PATCH] End of changes --- stix2/base.py | 4 +-- stix2/canonicalization/Canonicalize.py | 8 ++++-- stix2/datastore/filters.py | 34 ------------------------ stix2/test/v21/test_datastore_filters.py | 11 ++++++-- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/stix2/base.py b/stix2/base.py index f933d3b..4d4b080 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -393,12 +393,12 @@ class _Observable(_STIXBase): if streamlined_obj_vals: data = canonicalize(streamlined_obj_vals, utf8=False) - # print (str(type(data))) + + # try/except here to enable python 2 compatibility try: return required_prefix + six.text_type(uuid.uuid5(namespace, data)) except UnicodeDecodeError: return required_prefix + six.text_type(uuid.uuid5(namespace, six.binary_type(data))) - # return required_prefix + six.text_type(uuid.uuid5(namespace, data)) # We return None if there are no values specified for any of the id-contributing-properties return None diff --git a/stix2/canonicalization/Canonicalize.py b/stix2/canonicalization/Canonicalize.py index daf0616..78145be 100644 --- a/stix2/canonicalization/Canonicalize.py +++ b/stix2/canonicalization/Canonicalize.py @@ -24,6 +24,8 @@ import re +import six + from stix2.canonicalization.NumberToJson import convert2Es6Format try: @@ -395,7 +397,8 @@ def _make_iterencode( else: items = dct.items() for key, value in items: - if isinstance(key, str): + # Replaced isinstance(key, str) with below to enable simultaneous python 2 & 3 compatibility + if isinstance(key, six.string_types) or isinstance(key, six.binary_type): pass # JavaScript is weakly typed for these, so it makes sense to # also allow them. Many encoders seem to do something like this. @@ -454,7 +457,8 @@ def _make_iterencode( del markers[markerid] def _iterencode(o, _current_indent_level): - if isinstance(o, str): + # Replaced isinstance(o, str) with below to enable simultaneous python 2 & 3 compatibility + if isinstance(o, six.string_types) or isinstance(o, six.binary_type): yield _encoder(o) elif o is None: yield 'null' diff --git a/stix2/datastore/filters.py b/stix2/datastore/filters.py index 806f672..4f72b82 100644 --- a/stix2/datastore/filters.py +++ b/stix2/datastore/filters.py @@ -90,23 +90,6 @@ class Filter(collections.namedtuple('Filter', ['property', 'op', 'value'])): filter_value = self.value if self.op == "=": - boolA = stix_obj_property == filter_value - if boolA is False: - print ('$$$$$') - print (stix_obj_property) - print ('\n') - print (filter_value) - print ('\n') - print ('$$$$$') - pass - else: - # print ('222222222') - # print (stix_obj_property) - # print ('\n') - # print (filter_value) - # print ('\n') - # print ('222222222') - pass return stix_obj_property == filter_value elif self.op == "!=": return stix_obj_property != filter_value @@ -114,23 +97,6 @@ class Filter(collections.namedtuple('Filter', ['property', 'op', 'value'])): return stix_obj_property in filter_value elif self.op == "contains": if isinstance(filter_value, dict): - boolB = filter_value in stix_obj_property.values() - if boolB is False: - print ('@@@@@@') - print (filter_value) - print ('\n') - print (stix_obj_property.values()) - print ('\n') - print ('@@@@@@@') - pass - else: - # print ('55555555555') - # print (filter_value) - # print ('\n') - # print (stix_obj_property.values()) - # print ('\n') - # print ('55555555555') - pass return filter_value in stix_obj_property.values() else: return filter_value in stix_obj_property diff --git a/stix2/test/v21/test_datastore_filters.py b/stix2/test/v21/test_datastore_filters.py index 96ac17f..b7b41a0 100644 --- a/stix2/test/v21/test_datastore_filters.py +++ b/stix2/test/v21/test_datastore_filters.py @@ -89,6 +89,7 @@ stix_objs = [ "spec_version": "2.1", "id": "file--42a7175a-42cc-508f-8fa7-23b330aff876", "name": "HAL 9000.exe", + "defanged": False, }, }, @@ -111,8 +112,14 @@ filters = [ Filter("object_marking_refs", "=", "marking-definition--613f2e26-0000-4000-8000-b8e91df99dc9"), Filter("granular_markings.selectors", "in", "description"), Filter("external_references.source_name", "=", "CVE"), - Filter("objects", "=", {"0": {"type": "file", "id": "file--42a7175a-42cc-508f-8fa7-23b330aff876", "name": "HAL 9000.exe", "spec_version": "2.1"}}), - Filter("objects", "contains", {"type": "file", "id": "file--42a7175a-42cc-508f-8fa7-23b330aff876", "name": "HAL 9000.exe", "spec_version": "2.1"}), + Filter( + "objects", "=", + {"0": {"type": "file", "id": "file--42a7175a-42cc-508f-8fa7-23b330aff876", "name": "HAL 9000.exe", "spec_version": "2.1", "defanged": False}}, + ), + Filter( + "objects", "contains", + {"type": "file", "id": "file--42a7175a-42cc-508f-8fa7-23b330aff876", "name": "HAL 9000.exe", "spec_version": "2.1", "defanged": False}, + ), Filter("labels", "contains", "heartbleed"), ]