diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-11-26 11:40:09 -0500 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-11-26 11:40:09 -0500 |
commit | ec39437bfd7a710e5ac5d4e4ca3236391c90998a (patch) | |
tree | 9995591edf72f3ec2e5a1526af75e17c9db16150 /warlock | |
parent | d34e169d1eb97b6fa84acf39ec2722d9ce77eaba (diff) | |
download | warlock-ec39437bfd7a710e5ac5d4e4ca3236391c90998a.tar.gz |
Allow delattr and del operations
Diffstat (limited to 'warlock')
-rw-r--r-- | warlock/core.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/warlock/core.py b/warlock/core.py index da662ec..38cb854 100644 --- a/warlock/core.py +++ b/warlock/core.py @@ -76,7 +76,18 @@ def model_factory(schema): raise InvalidOperation() def __delitem__(self, key): - raise InvalidOperation() + mutation = dict(self.items()) + del mutation[key] + try: + self.validator(mutation) + except ValidationError: + msg = "Unable to delete attribute '%s'" % (key) + raise InvalidOperation(msg) + + dict.__delitem__(self, key) + + def __delattr__(self, key): + self.__delitem__(key) # NOTE(termie): This is kind of the opposite of what copy usually does def copy(self): |