<NME> core.py
<BEF> """Core Warlock functionality"""

#import jsonschema


def model_factory(schema):
import copy

    :param schema: dict representing valid JSON schema
    """
    class Model(object):
        """Self-validating model for arbitrary objects"""
        def __init__(self, **kwargs):
            self.__dict__['raw'] = kwargs

        def __getattr__(self, key):
            try:
            base_class.__init__(self, *args, **kwargs)

                raise AttributeError(key)

        def __setattr__(self, key, value):
            if key in self.__dict__['raw']:
                self.__dict__['raw'][key] = value
            else:
                raise AttributeError(key)

    Model.__name__ = schema['name']
    return Model

<MSG> Use jsonschema for operation validation

<DFF> @@ -1,6 +1,16 @@
 """Core Warlock functionality"""
 
-#import jsonschema
+import copy
+
+import jsonschema
+
+
+class InvalidOperation(RuntimeError):
+    pass
+
+
+class ValidationError(ValueError):
+    pass
 
 
 def model_factory(schema):
@@ -8,10 +18,25 @@ def model_factory(schema):
 
     :param schema: dict representing valid JSON schema
     """
+    schema = copy.deepcopy(schema)
+
+    def validator(obj):
+        """Apply a JSON schema to an object"""
+        try:
+            jsonschema.validate(obj, schema)
+        except jsonschema.ValidationError:
+            raise ValidationError()
+
     class Model(object):
         """Self-validating model for arbitrary objects"""
         def __init__(self, **kwargs):
-            self.__dict__['raw'] = kwargs
+            self.__dict__['validator'] = validator
+            try:
+                self.__dict__['validator'](kwargs)
+            except ValidationError:
+                raise ValueError()
+            else:
+                self.__dict__['raw'] = kwargs
 
         def __getattr__(self, key):
             try:
@@ -20,10 +45,13 @@ def model_factory(schema):
                 raise AttributeError(key)
 
         def __setattr__(self, key, value):
-            if key in self.__dict__['raw']:
-                self.__dict__['raw'][key] = value
-            else:
-                raise AttributeError(key)
+            mutation = copy.deepcopy(self.__dict__['raw'])
+            mutation[key] = value
+            try:
+                self.__dict__['validator'](mutation)
+            except ValidationError:
+                raise InvalidOperation()
+            self.__dict__['raw'] = mutation
 
     Model.__name__ = schema['name']
     return Model

Use jsonschema for operation validation