summaryrefslogtreecommitdiff
path: root/warlock/model.py
diff options
context:
space:
mode:
authorRob <rob.s.brit@gmail.com>2012-11-27 13:22:57 -0500
committerBrian Waldon <bcwaldon@gmail.com>2013-01-21 09:27:44 -0800
commitc2c446193089a717a9cbc3eeca73c1a30a0f7b6b (patch)
treebcbc79d2aac9b039f19a2e08f1cca2eaefbe9e90 /warlock/model.py
parent98a44c660136b7089cf3e8ed95254b475ab4d085 (diff)
downloadwarlock-c2c446193089a717a9cbc3eeca73c1a30a0f7b6b.tar.gz
Made validator inheritable by base classes.
Diffstat (limited to 'warlock/model.py')
-rw-r--r--warlock/model.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/warlock/model.py b/warlock/model.py
index 6dff70a..47dfeeb 100644
--- a/warlock/model.py
+++ b/warlock/model.py
@@ -3,15 +3,13 @@
import copy
import jsonpatch
+import jsonschema
import exceptions
class Model(dict):
def __init__(self, *args, **kwargs):
- # Load the validator from the kwargs
- #self.__dict__['validator'] = kwargs.pop('validator', self.default_validator)
-
# we overload setattr so set this manually
d = dict(*args, **kwargs)
@@ -104,5 +102,9 @@ class Model(dict):
original = self.__dict__['__original__']
return jsonpatch.make_patch(original, dict(self)).to_string()
- def default_validator(self, *args, **kwargs):
- return True
+ def validator(self, obj):
+ """Apply a JSON schema to an object"""
+ try:
+ jsonschema.validate(obj, self.schema)
+ except jsonschema.ValidationError as exc:
+ raise exceptions.ValidationError(str(exc))