Define CustomProperty. Make sure to update _properties dict when allow_custom=True
parent
cd6c7982af
commit
8c2af813b2
|
@ -40,14 +40,7 @@ class _STIXBase(collections.Mapping):
|
||||||
"""Base class for STIX object types"""
|
"""Base class for STIX object types"""
|
||||||
|
|
||||||
def object_properties(self):
|
def object_properties(self):
|
||||||
props = set(self._properties.keys())
|
return list(self._properties.keys())
|
||||||
custom_props = list(set(self._inner.keys()) - props)
|
|
||||||
custom_props.sort()
|
|
||||||
|
|
||||||
all_properties = list(self._properties.keys())
|
|
||||||
all_properties.extend(custom_props) # Any custom properties to the bottom
|
|
||||||
|
|
||||||
return all_properties
|
|
||||||
|
|
||||||
def _check_property(self, prop_name, prop, kwargs):
|
def _check_property(self, prop_name, prop, kwargs):
|
||||||
if prop_name not in kwargs:
|
if prop_name not in kwargs:
|
||||||
|
@ -109,6 +102,13 @@ class _STIXBase(collections.Mapping):
|
||||||
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
||||||
if extra_kwargs:
|
if extra_kwargs:
|
||||||
raise ExtraPropertiesError(cls, extra_kwargs)
|
raise ExtraPropertiesError(cls, extra_kwargs)
|
||||||
|
else:
|
||||||
|
from .properties import CustomProperty
|
||||||
|
|
||||||
|
# The custom properties will get added to the bottom.
|
||||||
|
# Matched with a CustomProperty.
|
||||||
|
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
||||||
|
self._properties.update([(x, CustomProperty()) for x in extra_kwargs])
|
||||||
|
|
||||||
# Remove any keyword arguments whose value is None
|
# Remove any keyword arguments whose value is None
|
||||||
setting_kwargs = {}
|
setting_kwargs = {}
|
||||||
|
|
|
@ -393,3 +393,15 @@ class PatternProperty(StringProperty):
|
||||||
raise ValueError(str(errors[0]))
|
raise ValueError(str(errors[0]))
|
||||||
|
|
||||||
return self.string_type(value)
|
return self.string_type(value)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomProperty(Property):
|
||||||
|
"""
|
||||||
|
The custom property class can be used as a base to extend further
|
||||||
|
functionality of a custom property.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
This class is used internally to signal the use of any custom property
|
||||||
|
that is parsed by any object or `parse()` method and allow_custom=True.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue