removed unecessary checks, (clearly I need to review python ref model)
parent
4734711137
commit
6df23e7268
|
@ -71,8 +71,7 @@ class Filter(collections.namedtuple("Filter", ['property', 'op', 'value'])):
|
||||||
|
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
# if value is a datetime obj, convert to str
|
# if value is a datetime obj, convert to str
|
||||||
dt_str = format_datetime(value)
|
value = format_datetime(value)
|
||||||
value = dt_str # use temp variable to avoid deepcopy operation
|
|
||||||
|
|
||||||
_check_filter_components(prop, op, value)
|
_check_filter_components(prop, op, value)
|
||||||
|
|
||||||
|
@ -90,11 +89,10 @@ class Filter(collections.namedtuple("Filter", ['property', 'op', 'value'])):
|
||||||
False otherwise.
|
False otherwise.
|
||||||
"""
|
"""
|
||||||
if isinstance(stix_obj_property, datetime):
|
if isinstance(stix_obj_property, datetime):
|
||||||
# if a datetime obj, use str format before comparison
|
# if a datetime obj, convert to str format before comparison
|
||||||
# NOTE: this check seems like it should be done upstream
|
# NOTE: this check seems like it should be done upstream
|
||||||
# but will put here for now
|
# but will put here for now
|
||||||
tmp = format_datetime(stix_obj_property)
|
stix_obj_property = format_datetime(stix_obj_property)
|
||||||
stix_obj_property = tmp # use tmp variable to avoid deepcopy op
|
|
||||||
|
|
||||||
if self.op == "=":
|
if self.op == "=":
|
||||||
return stix_obj_property == self.value
|
return stix_obj_property == self.value
|
||||||
|
@ -174,9 +172,6 @@ def _check_filter(filter_, stix_obj):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif isinstance(stix_obj[prop], dict):
|
|
||||||
return _check_filter(sub_filter, stix_obj[prop])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return _check_filter(sub_filter, stix_obj[prop])
|
return _check_filter(sub_filter, stix_obj[prop])
|
||||||
|
|
||||||
|
@ -242,8 +237,6 @@ class FilterSet(object):
|
||||||
if f not in self._filters:
|
if f not in self._filters:
|
||||||
self._filters.append(f)
|
self._filters.append(f)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def remove(self, filters=None):
|
def remove(self, filters=None):
|
||||||
"""remove a Filter, list of Filters, or FilterSet from the FilterSet
|
"""remove a Filter, list of Filters, or FilterSet from the FilterSet
|
||||||
|
|
||||||
|
@ -263,5 +256,3 @@ class FilterSet(object):
|
||||||
|
|
||||||
for f in filters:
|
for f in filters:
|
||||||
self._filters.remove(f)
|
self._filters.remove(f)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
|
@ -510,7 +510,7 @@ def test_datetime_filter_behavior():
|
||||||
filter_with_dt_obj = Filter("created", "=", parse_into_datetime("2016-02-14T00:00:00.000Z", "millisecond"))
|
filter_with_dt_obj = Filter("created", "=", parse_into_datetime("2016-02-14T00:00:00.000Z", "millisecond"))
|
||||||
filter_with_str = Filter("created", "=", "2016-02-14T00:00:00.000Z")
|
filter_with_str = Filter("created", "=", "2016-02-14T00:00:00.000Z")
|
||||||
|
|
||||||
# check taht filter value is converted from datetime to str
|
# check that filter value is converted from datetime to str
|
||||||
assert isinstance(filter_with_dt_obj.value, str)
|
assert isinstance(filter_with_dt_obj.value, str)
|
||||||
|
|
||||||
# compare datetime string to filter w/ datetime obj
|
# compare datetime string to filter w/ datetime obj
|
||||||
|
|
Loading…
Reference in New Issue