From 88f8ea3b4e29503bfb6956a4039358a1c9d03fa6 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 4 Apr 2024 08:53:39 -0400 Subject: [PATCH] Adding enumproperty to simple type and edit openvocabproperty --- stix2/properties.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stix2/properties.py b/stix2/properties.py index a535cd02..63458613 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -406,7 +406,7 @@ def __init__(self, valid_types=None, spec_version=DEFAULT_VERSION, **kwargs): simple_types = [ BinaryProperty, BooleanProperty, FloatProperty, HexProperty, IntegerProperty, StringProperty, - TimestampProperty, ReferenceProperty, + TimestampProperty, ReferenceProperty, EnumProperty ] if not valid_types: valid_types = [Property] @@ -722,7 +722,11 @@ def __init__(self, allowed, **kwargs): self.allowed = allowed super(EnumProperty, self).__init__(**kwargs) - def clean(self, value, allow_custom): + def clean(self, value, allow_custom, strict=False): + if not isinstance(value, str): + if strict is True: + raise ValueError("Must be a string.") + cleaned_value, _ = super(EnumProperty, self).clean(value, allow_custom) if cleaned_value not in self.allowed: @@ -743,7 +747,7 @@ def __init__(self, allowed, **kwargs): allowed = [allowed] self.allowed = allowed - def clean(self, value, allow_custom): + def clean(self, value, allow_custom, strict=False): cleaned_value, _ = super(OpenVocabProperty, self).clean( value, allow_custom, )