Make Immutable error more descriptive. Also fixes #13

stix2.1
Emmanuelle Vargas-Gonzalez 2017-06-01 12:43:06 -04:00
parent 9dbde93031
commit 49f58ff513
2 changed files with 9 additions and 3 deletions

View File

@ -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):

View File

@ -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):