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