[Checkins] SVN: z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/_ Provide combined reports of multiple errors within a single deserialization
Christian Theune
ct at gocept.com
Thu Oct 1 08:38:28 EDT 2009
Log message for revision 104678:
Provide combined reports of multiple errors within a single deserialization
run.
Changed:
U z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/__init__.py
U z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/_schema2xml.py
-=-
Modified: z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/__init__.py
===================================================================
--- z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/__init__.py 2009-10-01 12:31:46 UTC (rev 104677)
+++ z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/__init__.py 2009-10-01 12:38:27 UTC (rev 104678)
@@ -1,4 +1,5 @@
from _schema2xml import IXMLGenerator
from _schema2xml import serialize, serialize_to_tree
from _schema2xml import deserialize, deserialize_from_tree
+from _schema2xml import DeserializationError
from _schema2xml import GeneratedObject
Modified: z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/_schema2xml.py
===================================================================
--- z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/_schema2xml.py 2009-10-01 12:31:46 UTC (rev 104677)
+++ z3c.schema2xml/branches/combined-deserialization-errors/src/z3c/schema2xml/_schema2xml.py 2009-10-01 12:38:27 UTC (rev 104678)
@@ -24,12 +24,33 @@
return etree.tostring(
container, encoding=encoding, pretty_print=pretty_print)
+
+class DeserializationError(TypeError):
+ """Deserialization did not succeed.
+
+ The attribute `field_errors` contains a dictionary mapping field names to
+ an exception that occured.
+
+ """
+
+ def __init__(self, field_errors):
+ self.field_errors = field_errors
+
+
def deserialize_from_tree(container, schema, instance):
+ errors = {}
+
for element in container:
field = schema[element.tag]
- value = IXMLGenerator(field).input(element)
- field.set(instance, value)
+ try:
+ value = IXMLGenerator(field).input(element)
+ field.set(instance, value)
+ except Exception, e:
+ errors[field.__name__] = e
+ if errors:
+ raise DeserializationError(errors)
+
alsoProvides(instance, schema)
def deserialize(xml, schema, instance):
More information about the checkins
mailing list