本文整理汇总了Python中cybox.core.Object.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Object.to_dict方法的具体用法?Python Object.to_dict怎么用?Python Object.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cybox.core.Object
的用法示例。
在下文中一共展示了Object.to_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_round_trip
# 需要导入模块: from cybox.core import Object [as 别名]
# 或者: from cybox.core.Object import to_dict [as 别名]
def test_round_trip(self):
o = Object()
o.idref = "example:a1"
o.properties = Address("1.2.3.4", Address.CAT_IPV4)
o2 = cybox.test.round_trip(o)
self.assertEqual(o.to_dict(), o2.to_dict())
示例2: Observable
# 需要导入模块: from cybox.core import Object [as 别名]
# 或者: from cybox.core.Object import to_dict [as 别名]
#.........这里部分代码省略.........
def add_keyword(self, value):
self.keywords.append(value)
def to_obj(self, return_obj=None, ns_info=None):
self._collect_ns_info(ns_info)
obs_obj = core_binding.ObservableType()
obs_obj.id = self.id_
if self.title is not None:
obs_obj.Title = self.title
if self.description is not None:
obs_obj.Description = self.description.to_obj(ns_info=ns_info)
if self.object_:
obs_obj.Object = self.object_.to_obj(ns_info=ns_info)
if self.event:
obs_obj.Event = self.event.to_obj(ns_info=ns_info)
if self.observable_composition:
obs_obj.Observable_Composition = self.observable_composition.to_obj(ns_info=ns_info)
if self.idref is not None:
obs_obj.idref = self.idref
if self.sighting_count is not None:
obs_obj.sighting_count = self.sighting_count
if self.observable_source:
obs_obj.Observable_Source = [x.to_obj(ns_info=ns_info) for x in self.observable_source]
if self.keywords:
obs_obj.Keywords = self.keywords.to_obj(ns_info=ns_info)
if self.pattern_fidelity:
obs_obj.Pattern_Fidelity = self.pattern_fidelity.to_obj(ns_info=ns_info)
return obs_obj
def to_dict(self):
obs_dict = {}
if self.id_ is not None:
obs_dict['id'] = self.id_
if self.title is not None:
obs_dict['title'] = self.title
if self.description is not None:
obs_dict['description'] = self.description.to_dict()
if self.object_:
obs_dict['object'] = self.object_.to_dict()
if self.event:
obs_dict['event'] = self.event.to_dict()
if self.observable_composition:
obs_dict['observable_composition'] = self.observable_composition.to_dict()
if self.idref is not None:
obs_dict['idref'] = self.idref
if self.sighting_count is not None:
obs_dict['sighting_count'] = self.sighting_count
if self.observable_source:
obs_dict['observable_source'] = [x.to_dict() for x in self.observable_source]
if self.keywords:
obs_dict['keywords'] = self.keywords.to_dict()
if self.pattern_fidelity:
obs_dict['pattern_fidelity'] = self.pattern_fidelity.to_dict()
return obs_dict
@staticmethod
def from_obj(observable_obj):
if not observable_obj:
return None
示例3: Observable
# 需要导入模块: from cybox.core import Object [as 别名]
# 或者: from cybox.core.Object import to_dict [as 别名]
class Observable(cybox.Entity):
"""A single Observable.
"""
_binding = core_binding
_namespace = 'http://cybox.mitre.org/cybox-2'
def __init__(self, item=None, id_=None):
"""Create an Observable out of 'item'.
`item` can be any of:
- an Object
- an ObservableComposition
- any subclass of ObjectProperties.
In the first two cases, the appropriate property of the Observable will
be set. In the last cases, an Object will be built automatically to
ensure the correct hierarchy is created.
"""
if not id_:
id_ = cybox.utils.create_id(prefix="Observable")
self.id_ = id_
self.title = None
self.description = None
self.object_ = None
self.observable_composition = None
self.idref = None
if not item:
return
if isinstance(item, Object):
self.object_ = item
elif isinstance(item, ObservableComposition):
self.observable_composition = item
elif isinstance(item, ObjectProperties):
if item.parent:
self.object_ = item.parent
else:
self.object_ = Object(item)
@property
def object_(self):
return self._object
@object_.setter
def object_(self, value):
if value:
if self.observable_composition:
msg = 'Observable already has an ObservableComposition.'
raise ValueError(msg)
if not isinstance(value, Object):
raise TypeError('value must be a Object')
self._object = value
@property
def observable_composition(self):
return self._observable_composition
@observable_composition.setter
def observable_composition(self, value):
if value:
if self.object_:
raise ValueError('Observable already has an Object.')
if not isinstance(value, ObservableComposition):
raise TypeError('value must be an ObservableComposition')
self._observable_composition = value
@property
def description(self):
return self._description
@description.setter
def description(self, value):
if value is not None and not isinstance(value, StructuredText):
value = StructuredText(value)
self._description = value
def to_obj(self):
obs_obj = core_binding.ObservableType()
obs_obj.set_id(self.id_)
if self.title is not None:
obs_obj.set_Title(self.title)
if self.description is not None:
obs_obj.set_Description(self.description.to_obj())
if self.object_:
obs_obj.set_Object(self.object_.to_obj())
if self.observable_composition:
obs_obj.set_Observable_Composition(self.observable_composition.to_obj())
if self.idref is not None:
obs_obj.set_idref(self.idref)
return obs_obj
def to_dict(self):
obs_dict = {}
#.........这里部分代码省略.........