Make Immutable error more descriptive. Also fixes #13
parent
9dbde93031
commit
49f58ff513
|
@ -128,7 +128,7 @@ class _STIXBase(collections.Mapping):
|
|||
|
||||
def __setattr__(self, name, value):
|
||||
if name != '_inner' and not name.startswith("_STIXBase__"):
|
||||
raise ImmutableError
|
||||
raise ImmutableError(self.__class__, name)
|
||||
super(_STIXBase, self).__setattr__(name, value)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -47,8 +47,14 @@ class ExtraPropertiesError(STIXError, TypeError):
|
|||
class ImmutableError(STIXError, ValueError):
|
||||
"""Attempted to modify an object after creation"""
|
||||
|
||||
def __init__(self):
|
||||
super(ImmutableError, self).__init__("Cannot modify properties after creation.")
|
||||
def __init__(self, cls, key):
|
||||
super(ImmutableError, self).__init__()
|
||||
self.cls = cls
|
||||
self.key = key
|
||||
|
||||
def __str__(self):
|
||||
msg = "Cannot modify '{0.key}' property in {0.cls} after creation."
|
||||
return msg.format(self)
|
||||
|
||||
|
||||
class DictionaryKeyError(STIXError, ValueError):
|
||||
|
|
Loading…
Reference in New Issue