too Chris' suggestions to improve interproperty constraint methods
added interproperty constraint check to ExternalReferencesstix2.1
parent
29871427b7
commit
a95e91005c
|
@ -50,20 +50,15 @@ class _STIXBase(collections.Mapping):
|
|||
# interproperty constraint methods
|
||||
|
||||
def _check_mutually_exclusive_properties(self, list_of_properties, at_least_one=True):
|
||||
count = 0
|
||||
current_properties = self.properties_populated()
|
||||
for x in list_of_properties:
|
||||
if x in current_properties:
|
||||
count += 1
|
||||
count = len(set(list_of_properties).intersection(current_properties))
|
||||
# at_least_one allows for xor to be checked
|
||||
if count > 1 or (at_least_one and count == 0):
|
||||
raise MutuallyExclusivePropertiesError(self.__class__, list_of_properties)
|
||||
|
||||
def _check_at_least_one_property(self, list_of_properties):
|
||||
current_properties = self.properties_populated()
|
||||
for x in list_of_properties:
|
||||
if x in current_properties:
|
||||
return
|
||||
if not set(list_of_properties).intersection(current_properties):
|
||||
raise AtLeastOnePropertyError(self.__class__, list_of_properties)
|
||||
|
||||
def _check_properties_dependency(self, list_of_properties, list_of_dependent_properties, values=[]):
|
||||
|
|
|
@ -15,6 +15,10 @@ class ExternalReference(_STIXBase):
|
|||
'external_id': StringProperty(),
|
||||
}
|
||||
|
||||
def _check_object_constaints(self):
|
||||
super(ExternalReference, self)._check_object_constaints()
|
||||
self._check_at_least_one_property(["description", "external_id", "url"])
|
||||
|
||||
|
||||
class KillChainPhase(_STIXBase):
|
||||
_properties = {
|
||||
|
|
Loading…
Reference in New Issue