Skip to content

Commit eaa6c68

Browse files
author
Bryan Worrell
committed
Updated YaraTestMechanism to call _BaseTestMechanism correctly. Still need to update to TypedFields.
1 parent 0bde65d commit eaa6c68

2 files changed

Lines changed: 27 additions & 29 deletions

File tree

stix/extensions/test_mechanism/yara_test_mechanism.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,45 @@ def rule(self, value):
3535
self._rule = EncodedCDATA(value=value)
3636

3737
@classmethod
38-
def from_obj(cls, obj, return_obj=None):
39-
if not obj:
38+
def from_obj(cls, cls_obj):
39+
if not cls_obj:
4040
return None
41-
if not return_obj:
42-
return_obj = cls()
43-
44-
super(YaraTestMechanism, cls).from_obj(obj, return_obj)
45-
return_obj.version = obj.Version
46-
return_obj.rule = EncodedCDATA.from_obj(obj.Rule)
47-
48-
return return_obj
41+
42+
obj = super(YaraTestMechanism, cls).from_obj(cls_obj)
43+
44+
obj.version = cls_obj.Version
45+
obj.rule = EncodedCDATA.from_obj(cls_obj.Rule)
46+
47+
return obj
4948

50-
def to_obj(self, return_obj=None, ns_info=None):
51-
if not return_obj:
52-
return_obj = self._binding_class()
53-
54-
super(YaraTestMechanism, self).to_obj(return_obj=return_obj, ns_info=ns_info)
49+
def to_obj(self, ns_info=None):
50+
obj = super(YaraTestMechanism, self).to_obj(ns_info=ns_info)
5551

5652
if self.version:
57-
return_obj.Version = self.version
53+
obj.Version = self.version
5854
if self.rule:
59-
return_obj.Rule = self.rule.to_obj(ns_info=ns_info)
55+
obj.Rule = self.rule.to_obj(ns_info=ns_info)
6056

61-
return return_obj
57+
return obj
6258

6359
@classmethod
64-
def from_dict(cls, d, return_obj=None):
65-
if not d:
60+
def from_dict(cls, cls_dict):
61+
if not cls_dict:
6662
return None
67-
if not return_obj:
68-
return_obj = cls()
69-
70-
super(YaraTestMechanism, cls).from_dict(d, return_obj)
71-
return_obj.version = d.get('version')
72-
return_obj.rule = EncodedCDATA.from_dict(d.get('rule'))
63+
64+
obj = super(YaraTestMechanism, cls).from_dict(cls_dict)
65+
66+
obj.version = cls_dict.get('version')
67+
obj.rule = EncodedCDATA.from_dict(cls_dict.get('rule'))
7368

74-
return return_obj
69+
return obj
7570

7671
def to_dict(self):
7772
d = super(YaraTestMechanism, self).to_dict()
7873

7974
if self.version:
8075
d['version'] = self.version
76+
8177
if self.rule:
8278
d['rule'] = self.rule.to_dict()
8379

stix/indicator/test_mechanism.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import stix.bindings.indicator as indicator_binding
1414

1515

16-
class _BaseTestMechanism(Cached, entities.Entity):
16+
class _BaseTestMechanism(Cached, stix.Entity):
1717
_namespace = "http://stix.mitre.org/Indicator-2"
1818
_binding = indicator_binding
1919
_binding_class = indicator_binding.TestMechanismType()
@@ -24,7 +24,8 @@ class _BaseTestMechanism(Cached, entities.Entity):
2424
producer = fields.TypedField("Producer", InformationSource)
2525

2626
def __init__(self, id_=None, idref=None):
27-
self._fields = {}
27+
super(_BaseTestMechanism, self).__init__()
28+
2829
self.id_ = id_
2930
self.idref = idref
3031
self.efficacy = None
@@ -101,6 +102,7 @@ def entity_class(self, key):
101102
import stix.extensions.test_mechanism.generic_test_mechanism # noqa
102103
stix.lookup_extension(key)
103104

105+
104106
class TestMechanisms(stix.EntityList):
105107
_binding = indicator_binding
106108
_namespace = 'http://stix.mitre.org/Indicator-2'

0 commit comments

Comments
 (0)