Change __getattr__() to use __getitem__() instead. Other minor changes.
parent
d579c12172
commit
51e28f64da
|
@ -81,8 +81,7 @@ class _STIXBase(collections.Mapping):
|
||||||
raise DependentPropertiesError(self.__class__, failed_dependency_pairs)
|
raise DependentPropertiesError(self.__class__, failed_dependency_pairs)
|
||||||
|
|
||||||
def _check_object_constraints(self):
|
def _check_object_constraints(self):
|
||||||
if hasattr(self, "granular_markings") and self.granular_markings:
|
for m in self.get("granular_markings", []):
|
||||||
for m in self.granular_markings:
|
|
||||||
# TODO: check selectors
|
# TODO: check selectors
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -127,12 +126,12 @@ class _STIXBase(collections.Mapping):
|
||||||
|
|
||||||
# Handle attribute access just like key access
|
# Handle attribute access just like key access
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# If the requested attribute is not None return its value
|
try:
|
||||||
if self.get(name) is not None:
|
# Return attribute value.
|
||||||
return self.get(name)
|
return self.__getitem__(name)
|
||||||
# Otherwise check the attribute exists inside object. If it exists
|
except KeyError:
|
||||||
# return None. If not raise the AttributeError.
|
# If attribute not found, check if its a property of the object.
|
||||||
elif name in self._properties:
|
if name in self._properties:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
raise AttributeError("'%s' object has no attribute '%s'" %
|
raise AttributeError("'%s' object has no attribute '%s'" %
|
||||||
|
|
Loading…
Reference in New Issue