[Zope-Checkins] CVS: Zope3/lib/python/Schema - Exceptions.py:1.2 _Schema.py:1.2

Joachim Schmitz js@aixtraware.de
Tue, 25 Jun 2002 06:21:02 -0400


Update of /cvs-repository/Zope3/lib/python/Schema
In directory cvs.zope.org:/tmp/cvs-serv16614

Modified Files:
	Exceptions.py _Schema.py 
Log Message:
added new Schema validation and tests.


=== Zope3/lib/python/Schema/Exceptions.py 1.1 => 1.2 ===
 
 class ValidationError(Exception):
-    pass
+    def __init__(self,error_name):
+	Exception.__init__(self)
+	self.error_name=error_name
+	
+    def __cmp__(self,other):
+	return cmp(self.error_name, other.error_name)
+
+class ValidationErrorsAll(Exception):
+    def __init__(self,list):
+	Exception.__init__(self)
+	self.errors = list


=== Zope3/lib/python/Schema/_Schema.py 1.1 => 1.2 ===
 
-def validate(schema, values):
-    """Pass in field values in dictionary and validate whether they
-    conform to schema. Return validated values.
+def validateMapping(schema, values):
+    """Pass in field values in mapping and validate whether they
+    conform to schema. Stop at first error. 
     """
     from IField import IField
-    result = {}
     for name in schema.names(1):
         attr = schema.getDescriptionFor(name)
         if IField.isImplementedBy(attr):
-            result[name] = attr.validate(values.get(name))
-    return result
-    
+	    attr.validate(values.get(name))
+
+
+def validateMappingAll(schema, values):
+    """Pass in field values in mapping and validate whether they
+    conform to schema. 
+    """
+    list=[]
+    from IField import IField
+    for name in schema.names(1):
+        attr = schema.getDescriptionFor(name)
+        if IField.isImplementedBy(attr):
+	    try:
+		attr.validate(values.get(name))
+	    except ValidationError, e:
+		list.append((name, e))	
+    if len(list) > 0:
+	raise ValidationErrorsAll, list
+		
 # Now we can create the interesting interfaces and wire them up:
 def wire():