<NME> core.py
<BEF> # Copyright 2012 Brian Waldon
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Core Warlock functionality"""

import copy

from . import model
from jsonschema.validators import validator_for


def model_factory(schema, base_class=model.Model, name=None, resolver=None):
        """Apply a JSON schema to an object"""
        try:
            jsonschema.validate(obj, schema)
        except jsonschema.ValidationError:
            raise ValidationError()

    class Model(dict):
        """Self-validating model for arbitrary objects"""
    class Model(base_class):
        def __init__(self, *args, **kwargs):
            self.__dict__["schema"] = schema
            self.__dict__["resolver"] = resolver

            self.__dict__['validator'] = validator
            try:
                self.validator(d)
            except ValidationError:
                raise ValueError()
            else:
                dict.__init__(self, d)

    if resolver is not None:
        Model.resolver = resolver

    if name is not None:
        Model.__name__ = name
    elif "name" in schema:
        Model.__name__ = str(schema["name"])
    return Model
            try:
                self.validator(mutation)
            except ValidationError:
                raise InvalidOperation()

            dict.__setitem__(self, key, value)

            mutation.update(other)
            try:
                self.validator(mutation)
            except ValidationError:
                raise InvalidOperation()
            dict.update(self, other)

        def iteritems(self):

<MSG> Add helful text to Exceptions

Fixes issue #2

<DFF> @@ -24,8 +24,8 @@ def model_factory(schema):
         """Apply a JSON schema to an object"""
         try:
             jsonschema.validate(obj, schema)
-        except jsonschema.ValidationError:
-            raise ValidationError()
+        except jsonschema.ValidationError as exc:
+            raise ValidationError(str(exc))
 
     class Model(dict):
         """Self-validating model for arbitrary objects"""
@@ -37,8 +37,8 @@ def model_factory(schema):
             self.__dict__['validator'] = validator
             try:
                 self.validator(d)
-            except ValidationError:
-                raise ValueError()
+            except ValidationError as exc:
+                raise ValueError(str(exc))
             else:
                 dict.__init__(self, d)
 
@@ -56,7 +56,8 @@ def model_factory(schema):
             try:
                 self.validator(mutation)
             except ValidationError:
-                raise InvalidOperation()
+                msg = "Unable to set '%s' to '%s'" % (key, value)
+                raise InvalidOperation(msg)
 
             dict.__setitem__(self, key, value)
 
@@ -86,8 +87,8 @@ def model_factory(schema):
             mutation.update(other)
             try:
                 self.validator(mutation)
-            except ValidationError:
-                raise InvalidOperation()
+            except ValidationError as exc:
+                raise InvalidOperation(str(exc))
             dict.update(self, other)
 
         def iteritems(self):

Add helful text to Exceptions