Skip to content

Commit d45ff7e

Browse files
authored
Merge pull request #312 from emmanvg/new-objs-implementation
New objects implementation
2 parents 24eacac + 9fdbbf1 commit d45ff7e

File tree

16 files changed

+244
-29
lines changed

16 files changed

+244
-29
lines changed

cybox/bindings/cybox_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def exportChildren(self, lwrite, level, namespace_='cyboxCommon:', name_='Locati
220220
else:
221221
eol_ = ''
222222
if self.Name is not None:
223+
showIndent(lwrite, level, pretty_print)
223224
lwrite('<%sName>%s</%sName>%s' % ('cyboxCommon:', self.gds_format_string(quote_xml(self.Name), input_name='Name'), 'cyboxCommon:', eol_))
224225
def build(self, node):
225226
self.__sourcenode__ = node

cybox/bindings/cybox_core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,7 +3193,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
31933193
if nodeName_ == 'Event':
31943194
obj_ = EventType.factory()
31953195
obj_.build(child_)
3196-
self.Event.append(obj_)
3196+
self.add_Event(obj_)
31973197
# end class EventPoolType
31983198

31993199
class ActionPoolType(GeneratedsSuper):
@@ -3266,7 +3266,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
32663266
if nodeName_ == 'Action':
32673267
obj_ = ActionType.factory()
32683268
obj_.build(child_)
3269-
self.Action.append(obj_)
3269+
self.add_Action(obj_)
32703270
# end class ActionPoolType
32713271

32723272
class ObjectPoolType(GeneratedsSuper):
@@ -3339,7 +3339,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
33393339
if nodeName_ == 'Object':
33403340
obj_ = ObjectType.factory()
33413341
obj_.build(child_)
3342-
self.set_Object(obj_)
3342+
self.add_Object(obj_)
33433343
# end class ObjectPoolType
33443344

33453345
class PropertyPoolType(GeneratedsSuper):
@@ -3410,9 +3410,9 @@ def buildAttributes(self, node, attrs, already_processed):
34103410
pass
34113411
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
34123412
if nodeName_ == 'Property':
3413-
obj_ = ActionPertinentObjectPropertyType.factory()
3413+
obj_ = cybox_common.PropertyType.factory()
34143414
obj_.build(child_)
3415-
self.Property.append(obj_)
3415+
self.add_Property(obj_)
34163416
# end class PropertyPoolType
34173417

34183418
class ObfuscationTechniquesType(GeneratedsSuper):

cybox/common/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .digitalsignature import DigitalSignature, DigitalSignatureList
3535
from .environment_variable import EnvironmentVariable, EnvironmentVariableList
3636
from .hashes import Hash, HashList, HashName
37+
from .location import Location
3738
from .object_properties import ObjectProperties, Property
3839
from .structured_text import StructuredText
3940
from .time import Time

cybox/common/location.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
2+
# See LICENSE.txt for complete terms.
3+
4+
from mixbox import entities, fields
5+
6+
import cybox.bindings.cybox_common as common_binding
7+
8+
9+
class Location(entities.Entity):
10+
_binding = common_binding
11+
_binding_class = common_binding.LocationType
12+
_namespace = 'http://cybox.mitre.org/common-2'
13+
_XSI_TYPE = None # overridden by subclasses
14+
15+
id_ = fields.IdrefField("id")
16+
idref = fields.IdrefField("idref")
17+
name = fields.TypedField("Name")
18+
19+
def to_dict(self):
20+
d = super(Location, self).to_dict()
21+
22+
if self._XSI_TYPE:
23+
d["xsi:type"] = self._XSI_TYPE
24+
25+
return d

cybox/common/vocabs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def is_plain(self):
120120
121121
"""
122122
return (
123-
(self.xsi_type is None or type(self)._XSI_TYPE == self.xsi_type) and
123+
self.xsi_type is None and
124124
self.vocab_name is None and
125125
self.vocab_reference is None and
126126
super(VocabString, self).is_plain()
@@ -149,6 +149,7 @@ def from_obj(cls, cls_obj):
149149
#: Mapping of Controlled Vocabulary xsi:type's to their class implementations.
150150
_VOCAB_MAP = {}
151151

152+
152153
def _get_terms(vocab_class):
153154
"""Helper function used by register_vocab."""
154155
for k, v in vocab_class.__dict__.items():

cybox/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
from .event import Event, EventType
1818
from .pattern_fidelity import (PatternFidelity, ObfuscationTechniques,
1919
ObfuscationTechnique)
20+
from .pool import ActionPool, EventPool, PropertyPool, ObjectPool, Pools
2021
from .observable import Observable, Observables, ObservableComposition

cybox/core/action.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AssociatedObjects(entities.EntityList):
4343
_namespace = 'http://cybox.mitre.org/cybox-2'
4444
associated_object = fields.TypedField("Associated_Object", AssociatedObject, multiple=True)
4545

46+
4647
class ActionRelationship(entities.Entity):
4748
_binding = core_binding
4849
_binding_class = _binding.ActionRelationshipType
@@ -59,6 +60,7 @@ class ActionRelationships(entities.EntityList):
5960
_namespace = 'http://cybox.mitre.org/cybox-2'
6061
relationship = fields.TypedField("Relationship", ActionRelationship, multiple=True)
6162

63+
6264
class Action(entities.Entity):
6365
_binding = core_binding
6466
_binding_class = core_binding.ActionType
@@ -84,4 +86,4 @@ class Action(entities.Entity):
8486
class Actions(entities.EntityList):
8587
_binding_class = core_binding.ActionsType
8688
_namespace = 'http://cybox.mitre.org/cybox-2'
87-
action = fields.TypedField("Action", Action, multiple=True)
89+
action = fields.TypedField("Action", Action, multiple=True)

cybox/core/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mixbox import fields
66

77
import cybox.bindings.cybox_core as core_binding
8-
from cybox.common import StructuredText, MeasureSource
8+
from cybox.common import StructuredText, MeasureSource, Location
99
from cybox.common.vocabs import EventType, VocabField
1010
from cybox.core import Actions, Frequency
1111

@@ -23,7 +23,7 @@ class Event(entities.Entity):
2323
observation_method = fields.TypedField("Observation_Method", MeasureSource)
2424
actions = fields.TypedField("Actions", Actions)
2525
frequency = fields.TypedField("Frequency", Frequency)
26-
26+
location = fields.TypedField("Location", Location)
2727
event = fields.TypedField("Event", multiple=True)
2828

2929
# Allow recursive definition of events

cybox/core/object.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,8 @@ def to_obj(self, ns_info=None):
210210

211211
def to_dict(self):
212212
d = super(DomainSpecificObjectProperties, self).to_dict()
213-
d['xsi:type'] = self._XSI_TYPE
213+
214+
if self._XSI_TYPE:
215+
d['xsi:type'] = self._XSI_TYPE
216+
214217
return d

cybox/core/observable.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
22
# See LICENSE.txt for complete terms.
3-
import collections
43

5-
from mixbox import entities
6-
from mixbox import fields
7-
from mixbox import idgen
4+
from mixbox import entities, fields, idgen
85

96
from cybox import Unicode
107
import cybox.bindings.cybox_core as core_binding
@@ -127,15 +124,14 @@ def add_keyword(self, value):
127124

128125
class Observables(entities.EntityList):
129126
"""The root CybOX Observables object.
130-
131-
Pools are not currently supported.
132127
"""
133128
_binding = core_binding
134129
_binding_class = _binding.ObservablesType
135130
_namespace = 'http://cybox.mitre.org/cybox-2'
136131

137132
observable_package_source = fields.TypedField("Observable_Package_Source", MeasureSource)
138133
observables = fields.TypedField("Observable", Observable, multiple=True, key_name="observables")
134+
pools = fields.TypedField("Pools", type_="cybox.core.pool.Pools")
139135

140136
def __init__(self, observables=None):
141137
super(Observables, self).__init__(observables)
@@ -144,12 +140,19 @@ def __init__(self, observables=None):
144140
self._minor_version = 1
145141
self._update_version = 0
146142

147-
def add(self, observable):
148-
if not observable:
143+
def add(self, object_):
144+
from cybox.core.pool import Pools
145+
if not object_:
149146
return
150-
if not isinstance(observable, Observable):
151-
observable = Observable(observable)
152-
self.observables.append(observable)
147+
elif isinstance(object_, MeasureSource):
148+
self.observable_package_source = object_
149+
return
150+
elif isinstance(object_, Pools):
151+
self.pools = object_
152+
return
153+
elif not isinstance(object_, Observable):
154+
object_ = Observable(object_)
155+
self.observables.append(object_)
153156

154157
def to_obj(self, ns_info=None):
155158
observables_obj = super(Observables, self).to_obj(ns_info=ns_info)
@@ -190,4 +193,3 @@ def add(self, observable):
190193
if not observable:
191194
raise ValueError("'observable' must not be None")
192195
self.append(observable)
193-

0 commit comments

Comments
 (0)