[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/schema/_field.py
Merged r25315 from trunk.
Garrett Smith
garrett at mojave-corp.com
Wed Jun 9 15:43:08 EDT 2004
Log message for revision 25316:
Merged r25315 from trunk.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/schema/_field.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/schema/_field.py 2004-06-09 19:15:56 UTC (rev 25315)
+++ Zope3/branches/ZopeX3-3.0/src/zope/schema/_field.py 2004-06-09 19:43:07 UTC (rev 25316)
@@ -249,27 +249,44 @@
raise WrongType
def _validate_sequence(value_type, value, errors=None):
+ """Validates a sequence value.
+
+ Returns a list of validation errors generated during the validation. If
+ no errors are generated, returns an empty list.
+
+ value_type is a field. value is the sequence being validated. errors is
+ an optional list of errors that will be prepended to the return value.
+
+ To illustrate, we'll use a text value type. All values must be unicode.
+
+ >>> field = TextLine(required=True)
+
+ To validate a sequence of various values:
+
+ >>> errors = _validate_sequence(field, ('foo', u'bar', 1))
+ >>> errors
+ [foo <type 'unicode'>, 1 <type 'unicode'>]
+
+ The only valid value in the sequence is the second item. The others
+ generated errors.
+
+ We can use the optional errors argument to collect additional errors
+ for a new sequence:
+
+ >>> errors = _validate_sequence(field, (2, u'baz'), errors)
+ >>> errors
+ [foo <type 'unicode'>, 1 <type 'unicode'>, 2 <type 'unicode'>]
+
+ """
if errors is None:
errors = []
-
if value_type is None:
return errors
-
for item in value:
- error = None
try:
value_type.validate(item)
except ValidationError, error:
- pass
- else:
- # We validated, so clear error (if any) and done with
- # this value
- error = None
- break
-
- if error is not None:
errors.append(error)
-
return errors
def _validate_uniqueness(value):
More information about the Zope3-Checkins
mailing list