本文整理汇总了Python中stix.common.InformationSource.to_obj方法的典型用法代码示例。如果您正苦于以下问题:Python InformationSource.to_obj方法的具体用法?Python InformationSource.to_obj怎么用?Python InformationSource.to_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stix.common.InformationSource
的用法示例。
在下文中一共展示了InformationSource.to_obj方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Indicator
# 需要导入模块: from stix.common import InformationSource [as 别名]
# 或者: from stix.common.InformationSource import to_obj [as 别名]
#.........这里部分代码省略.........
return None
def add_observable(self, observable):
''' Adds an observable to the Indicator. If the number of observables associated with this indicator
is greater than one, the indicator will nest all of its observables under a parent observable
composition, with an logical operator of 'OR'. If this is not ideal, an separate indicator
should be made for each observable'''
if isinstance(observable, Observable):
self.observables.append(observable)
else:
# try to cast it to an Observable type
self.observables.append(Observable(observable))
def _merge_observables(self, observables):
observable_composition = ObservableComposition()
observable_composition.operator = self.observable_composition_operator
for observable_ in observables:
observable_composition.add(observable_)
root_observable = Observable()
root_observable.observable_composition = observable_composition
return root_observable
def add_object(self, object_):
''' The object paramter is wrapped in an observable and attached to the indicator. The object must be a
cybox.core.DefinedObject instance'''
observable = Observable(object_)
self.add_observable(observable)
def to_obj(self, return_obj=None):
if not return_obj:
return_obj = self._binding_class()
return_obj.set_id(self.id_)
return_obj.set_idref(self.idref)
return_obj.set_timestamp(dates.serialize_value(self.timestamp))
return_obj.set_Title(self.title)
if self.version:
return_obj.set_version(self._version)
if self.description:
return_obj.set_Description(self.description.to_obj())
if self.short_description:
return_obj.set_Short_Description(self.short_description.to_obj())
if self.confidence:
return_obj.set_Confidence(self.confidence.to_obj())
if self.indicator_types:
for indicator_type in self.indicator_types:
tmp_indicator_type = indicator_type.to_obj()
return_obj.add_Type(tmp_indicator_type)
if self.indicated_ttps:
return_obj.set_Indicated_TTP([x.to_obj() for x in self.indicated_ttps])
if self.observables:
if len(self.observables) > 1:
root_observable = self._merge_observables(self.observables)
else:
root_observable = self.observables[0]
return_obj.set_Observable(root_observable.to_obj())
if self.producer:
return_obj.set_Producer(self.producer.to_obj())
if self.test_mechanisms:
tms_obj = self._binding.TestMechanismsType()
示例2: Indicator
# 需要导入模块: from stix.common import InformationSource [as 别名]
# 或者: from stix.common.InformationSource import to_obj [as 别名]
#.........这里部分代码省略.........
return None
def add_observable(self, observable):
''' Adds an observable to the Indicator. If the number of observables associated with this indicator
is greater than one, the indicator will nest all of its observables under a parent observable
composition, with an logical operator of 'OR'. If this is not ideal, an separate indicator
should be made for each observable'''
if not isinstance(observable, Observable):
raise ValueError('observable must be instance of Observable')
self.observables.append(observable)
def _merge_observables(self, observables, operator='AND'):
observable_composition = ObservableComposition()
observable_composition.operator = operator
for observable_ in observables:
observable_composition.add(observable_)
root_observable = Observable()
root_observable.observable_composition = observable_composition
return root_observable
def add_object(self, object_):
''' The object paramter is wrapped in an observable and attached to the indicator. The object must be a
cybox.core.DefinedObject instance'''
observable = Observable(object_)
self.add_observable(observable)
def to_obj(self, return_obj=None):
if not return_obj:
return_obj = indicator_binding.IndicatorType()
if self.id_:
return_obj.set_id(self.id_)
if self.description:
return_obj.set_Description(self.description.to_obj())
if self.indicator_type:
return_obj.set_Type(self.indicator_type.to_obj())
return_obj.set_Title(self.title)
if self.observables:
if len(self.observables) > 1:
root_observable = self._merge_observables(self.observables)
else:
root_observable = self.observables[0]
return_obj.set_Observable(root_observable.to_obj())
if self.producer:
return_obj.set_Producer(self.producer.to_obj())
return return_obj
@classmethod
def from_obj(cls, obj, return_obj=None):
if not obj:
return None
示例3: Indicator
# 需要导入模块: from stix.common import InformationSource [as 别名]
# 或者: from stix.common.InformationSource import to_obj [as 别名]
#.........这里部分代码省略.........
observable_composition.add(observable)
root_observable = Observable()
root_observable.observable_composition = observable_composition
return root_observable
def add_object(self, object_):
"""Adds a python-cybox Object instance to the ``observables`` list
property.
This is the same as calling ``indicator.add_observable(object_)``.
Note:
If the `object` param is not an instance of ``cybox.core.Object``
an attempt will be made to to convert it into one before wrapping
it in an ``cybox.core.Observable`` layer.
Args:
object_: An instance of ``cybox.core.Object`` or an object
that can be converted into an instance of
``cybox.core.Observable``
Raises:
ValueError: if the `object_` param cannot be converted to an
instance of ``cybox.core.Observable``.
"""
if not object_:
return
observable = Observable(object_)
self.add_observable(observable)
def to_obj(self, return_obj=None, ns_info=None):
if not return_obj:
return_obj = self._binding_class()
super(Indicator, self).to_obj(return_obj=return_obj, ns_info=ns_info)
return_obj.negate = True if self.negate else None
if self.confidence:
return_obj.Confidence = self.confidence.to_obj(ns_info=ns_info)
if self.indicator_types:
return_obj.Type = self.indicator_types.to_obj(ns_info=ns_info)
if self.indicated_ttps:
return_obj.Indicated_TTP = self.indicated_ttps.to_obj(ns_info=ns_info)
if self.producer:
return_obj.Producer = self.producer.to_obj(ns_info=ns_info)
if self.test_mechanisms:
return_obj.Test_Mechanisms = self.test_mechanisms.to_obj(ns_info=ns_info)
if self.likely_impact:
return_obj.Likely_Impact = self.likely_impact.to_obj(ns_info=ns_info)
if self.alternative_id:
return_obj.Alternative_ID = self.alternative_id
if self.valid_time_positions:
return_obj.Valid_Time_Position = self.valid_time_positions.to_obj(ns_info=ns_info)
if self.suggested_coas:
return_obj.Suggested_COAs = self.suggested_coas.to_obj(ns_info=ns_info)
if self.sightings:
return_obj.Sightings = self.sightings.to_obj(ns_info=ns_info)
if self.composite_indicator_expression:
return_obj.Composite_Indicator_Expression = self.composite_indicator_expression.to_obj(ns_info=ns_info)
if self.kill_chain_phases:
return_obj.Kill_Chain_Phases = self.kill_chain_phases.to_obj(ns_info=ns_info)
if self.related_indicators: