55from cybox .core import Observable , ObservableComposition
66from cybox .common import Time
77
8-
98class Indicator (stix .Entity ):
109 TYPE_SOURCE_ORG = 0
1110 TYPE_SOURCE_PERSON = 1
1211 TYPES_SOURCE = (TYPE_SOURCE_ORG , TYPE_SOURCE_PERSON )
1312
14- def __init__ (self , id = None , producer = None , observables = None ):
15- self ._id = id if id else stix .utils .create_id ()
13+ def __init__ (self , id_ = None , producer = None , observables = None ):
14+ self .id_ = id_ if id_ is not None else stix .utils .create_id ()
1615 self .producer = producer if producer else stix .common .InformationSource ()
1716 self .observables = observables
1817 self .name = None
@@ -39,27 +38,27 @@ def observables(self, valuelist):
3938
4039 if valuelist :
4140 for value in valuelist :
42- self .add_observable (observable )
41+ self .add_observable (value )
4342
44- def add_source (self , type , name ):
43+ def add_source (self , type_ , name ):
4544 '''
4645 Adds a source to this indicator.
4746
4847 Keyword arguments:
49- type -- the type of source (Indicator.TYPE_SOURCE_ORG, Indicator.TYPE_SOURCE_PERSON)
48+ type_ -- the type_ of source (Indicator.TYPE_SOURCE_ORG, Indicator.TYPE_SOURCE_PERSON)
5049 name -- the name of the source
5150 '''
52- if type not in self .TYPES_SOURCE :
53- raise ValueError ('type not known' )
51+ if type_ not in self .TYPES_SOURCE :
52+ raise ValueError ('type_ not known' )
5453
55- if type == TYPE_SOURCE_ORG :
56- org_name_element = stix .common .OrganisationNameElement (org_name )
54+ if type_ == self . TYPE_SOURCE_ORG :
55+ org_name_element = stix .common .OrganisationNameElement (value = name )
5756 org_name = stix .common .OrganisationName ()
5857 org_name .add_organisation_name_element (org_name_element )
5958 self .producer .identity .party_name .add_organisation_name (org_name )
6059
61- if type == TYPE_SOURCE_PERSON :
62- person_name_element = stix .common .PersonNameElement (person_name )
60+ if type_ == self . TYPE_SOURCE_PERSON :
61+ person_name_element = stix .common .PersonNameElement (value = name )
6362 person_name = stix .common .PersonName ()
6463 person_name .add_name_element (person_name_element )
6564 self .producer .identity .party_name .add_person_name (person_name )
@@ -94,7 +93,7 @@ def get_sources(self):
9493
9594 # get the namelines
9695 try :
97- part_name = self .producer .identity .party_name
96+ party_name = self .producer .identity .party_name
9897 list_names .extend (party_name .name_lines )
9998 except :
10099 pass
@@ -152,14 +151,20 @@ def _merge_observables(self, observables, operator='AND'):
152151
153152 return root_observable
154153
155- def add_object (self , object ):
154+ def add_object (self , object_ ):
156155 ''' The object paramter is wrapped in an observable and attached to the indicator. The object must be a
157156 cybox.core.DefinedObject instance'''
158157
159- observable = Observable (stateful_measure = object )
158+ observable = Observable (stateful_measure = object_ )
160159 self .add_observable (observable )
161160
162- def to_obj (self , return_obj = stix_indicator_binding .IndicatorType ()):
161+ def to_obj (self , return_obj = None ):
162+ if not return_obj :
163+ return_obj = stix_indicator_binding .IndicatorType ()
164+
165+ if self .id_ :
166+ return_obj .set_id (self .id_ )
167+
163168 '''most of this does not work because of the state of the cybox api development'''
164169 if self .observables :
165170 observables_obj = stix_indicator_binding .ObservablesType ()
@@ -184,6 +189,8 @@ def from_obj(cls, obj, return_obj=None):
184189 if not return_obj :
185190 return_obj = cls ()
186191
192+ return_obj .id_ = obj .get_id ()
193+
187194 if obj .get_Producer ():
188195 return_obj .producer = stix .common .InformationSource .from_obj (obj .get_Producer ())
189196
@@ -198,6 +205,9 @@ def to_dict(self, return_dict=None):
198205 if not return_dict :
199206 return_dict = {}
200207
208+ if self .id_ :
209+ return_dict ['id' ] = self .id_
210+
201211 if self .observables :
202212 if len (self .observables ) == 1 :
203213 return_dict ['observable' ] = self .observables [0 ].to_dict ()
@@ -219,6 +229,8 @@ def from_dict(cls, dict_repr, return_obj=None):
219229 if not return_obj :
220230 return_obj = cls ()
221231
232+ return_obj .id_ = dict_repr .get ('id' , None )
233+
222234 observable_dict = dict_repr .get ('observable' , )
223235 producer_dict = dict_repr .get ('producer' , None )
224236
0 commit comments