[Zope3-checkins] CVS: Zope3/src/zope/schema - _bootstrapfields.py:1.28 _field.py:1.32 vocabulary.py:1.21

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Apr 11 06:35:05 EDT 2004


Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv4752/src/zope/schema

Modified Files:
	_bootstrapfields.py _field.py vocabulary.py 
Log Message:


Converted all name usages to use the newly created error classes.




=== Zope3/src/zope/schema/_bootstrapfields.py 1.27 => 1.28 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.27	Mon Mar 15 13:12:39 2004
+++ Zope3/src/zope/schema/_bootstrapfields.py	Sun Apr 11 06:35:04 2004
@@ -19,10 +19,16 @@
 import warnings
 
 from zope.interface import Attribute, providedBy, implements
-from zope.schema._bootstrapinterfaces import StopValidation, ValidationError
+from zope.schema._bootstrapinterfaces import StopValidation
 from zope.schema._bootstrapinterfaces import IFromUnicode
+from zope.schema._bootstrapinterfaces import RequiredMissing, WrongType
+from zope.schema._bootstrapinterfaces import ConstraintNotSatisfied
+from zope.schema._bootstrapinterfaces import NotAContainer, NotAnIterator
+from zope.schema._bootstrapinterfaces import TooSmall, TooBig
+from zope.schema._bootstrapinterfaces import TooShort, TooLong
+from zope.schema._bootstrapinterfaces import InvalidValue
+
 from zope.schema._schema import getFields
-from zope.schema import errornames
 
 class ValidatedProperty:
 
@@ -150,7 +156,7 @@
     def validate(self, value):
         if value == self.missing_value:
             if self.required:
-                raise ValidationError(errornames.RequiredMissing)
+                raise RequiredMissing
         else:
             try:
                 self._validate(value)
@@ -180,10 +186,10 @@
 
     def _validate(self, value):
         if self._type is not None and not isinstance(value, self._type):
-            raise ValidationError(errornames.WrongType, value, self._type)
+            raise WrongType(value, self._type)
 
         if self.constraint is not None and not self.constraint(value):
-            raise ValidationError(errornames.ConstraintNotSatisfied, value)
+            raise ConstraintNotSatisfied(value)
 
     def get(self, object):
         return getattr(object, self.__name__)
@@ -209,7 +215,7 @@
             try:
                 iter(value)
             except TypeError:
-                raise ValidationError(errornames.NotAContainer, value)
+                raise NotAContainer(value)
 
 
 class Iterable(Container):
@@ -221,7 +227,7 @@
         try:
             iter(value)
         except TypeError:
-            raise ValidationError(errornames.NotAnIterator, value)
+            raise NotAnIterator(value)
 
 
 class Orderable:
@@ -257,10 +263,10 @@
         super(Orderable, self)._validate(value)
 
         if self.min is not None and value < self.min:
-            raise ValidationError(errornames.TooSmall, value, self.min)
+            raise TooSmall(value, self.min)
 
         if self.max is not None and value > self.max:
-            raise ValidationError(errornames.TooBig, value, self.max)
+            raise TooBig(value, self.max)
 
 
 class MinMaxLen:
@@ -280,10 +286,10 @@
         super(MinMaxLen, self)._validate(value)
 
         if self.min_length is not None and len(value) < self.min_length:
-            raise ValidationError(errornames.TooShort, value, self.min_length)
+            raise TooShort(value, self.min_length)
 
         if self.max_length is not None and len(value) > self.max_length:
-            raise ValidationError(errornames.TooLong, value, self.max_length)
+            raise TooLong(value, self.max_length)
 
 
 class Enumerated:
@@ -330,8 +336,7 @@
         super(Enumerated, self)._validate(value)
         if self.allowed_values:
             if not value in self.allowed_values:
-                raise ValidationError(errornames.InvalidValue, value,
-                                      self.allowed_values)
+                raise InvalidValue(value, self.allowed_values)
 
 class Text(MinMaxLen, Field):
     """A field containing text used for human discourse."""
@@ -348,13 +353,13 @@
         >>> t.fromUnicode("foo x spam")
         Traceback (most recent call last):
         ...
-        ValidationError: (u'Wrong type', 'foo x spam', <type 'unicode'>)
+        WrongType: ('foo x spam', <type 'unicode'>)
         >>> t.fromUnicode(u"foo x spam")
         u'foo x spam'
         >>> t.fromUnicode(u"foo spam")
         Traceback (most recent call last):
         ...
-        ValidationError: (u'Constraint not satisfied', u'foo spam')
+        ConstraintNotSatisfied: foo spam
         """
         self.validate(str)
         return str


=== Zope3/src/zope/schema/_field.py 1.31 => 1.32 ===
--- Zope3/src/zope/schema/_field.py:1.31	Mon Mar 15 13:12:40 2004
+++ Zope3/src/zope/schema/_field.py	Sun Apr 11 06:35:04 2004
@@ -25,10 +25,6 @@
 from zope.interface.interfaces import IInterface
 from zope.interface.interfaces import IMethod
 
-from zope.schema.interfaces import ValidationError
-from zope.schema.errornames import WrongContainedType, WrongType
-from zope.schema import errornames
-
 from zope.schema.interfaces import IField
 from zope.schema.interfaces import IMinMaxLen, IText, ITextLine
 from zope.schema.interfaces import ISourceText
@@ -41,6 +37,11 @@
 from zope.schema.interfaces import IEnumeratedInt, IEnumeratedFloat
 from zope.schema.interfaces import IURI, IId, IFromUnicode
 
+from zope.schema.interfaces import ValidationError, InvalidValue
+from zope.schema.interfaces import WrongType, WrongContainedType
+from zope.schema.interfaces import SchemaNotProvided, SchemaNotFullyImplemented
+from zope.schema.interfaces import InvalidURI, InvalidId, InvalidDottedName
+
 from zope.schema._bootstrapfields import Field, Container, Iterable, Orderable
 from zope.schema._bootstrapfields import MinMaxLen, Enumerated
 from zope.schema._bootstrapfields import Text, TextLine, Bool, Int, Password
@@ -87,7 +88,7 @@
         >>> b.fromUnicode(u" foo y.z bat")
         Traceback (most recent call last):
         ...
-        ValidationError: (u'Constraint not satisfied', ' foo y.z bat')
+        ConstraintNotSatisfied:  foo y.z bat
 
         """
         v = str(u)
@@ -116,13 +117,13 @@
         >>> ascii._validate(umlauts)
         Traceback (most recent call last):
         ...
-        ValidationError: Invalid value
+        InvalidValue
         """
         super(ASCII, self)._validate(value)
         if not value:
             return
         if not max(map(ord, value)) < 128:
-            raise ValidationError(errornames.InvalidValue)
+            raise InvalidValue
 
 class BytesLine(Bytes):
     """A Text field with no newlines."""
@@ -188,7 +189,7 @@
     def _validate(self, value):
         super(InterfaceField, self)._validate(value)
         if not IInterface.providedBy(value):
-            raise ValidationError(WrongType)
+            raise WrongType
 
 def _validate_sequence(value_type, value, errors=None):
     if errors is None:
@@ -231,7 +232,7 @@
         super(Sequence, self)._validate(value)
         errors = _validate_sequence(self.value_type, value)
         if errors:
-            raise ValidationError(WrongContainedType, errors)
+            raise WrongContainedType, errors
 
 class Tuple(Sequence):
     """A field representing a Tuple."""
@@ -259,8 +260,7 @@
                 errors.append(error)
             except AttributeError, error:
                 # property for the given name is not implemented
-                errors.append(errornames.SchemaNotFullyImplemented)
-                
+                errors.append(SchemaNotFullyImplemented())
     return errors
 
 
@@ -270,7 +270,7 @@
 
     def __init__(self, schema, **kw):
         if not IInterface.providedBy(schema):
-            raise ValidationError(WrongType)
+            raise WrongType
             
         self.schema = schema
         super(Object, self).__init__(**kw)
@@ -280,12 +280,12 @@
         
         # schema has to be implemented by value    
         if not self.schema.providedBy(value):
-            raise ValidationError(errornames.SchemaNotProvided)
+            raise SchemaNotProvided
             
-        # check the value against  schema
+        # check the value against schema
         errors = _validate_fields(self.schema, value)
         if errors:
-            raise ValidationError(WrongContainedType, errors)
+            raise WrongContainedType(errors)
 
 
 class Dict(MinMaxLen, Iterable, Field):
@@ -315,7 +315,7 @@
             errors = _validate_sequence(self.key_type, value, errors)
 
             if errors:
-                raise ValidationError(WrongContainedType, errors)
+                raise WrongContainedType, errors
 
         finally:
             errors = None
@@ -339,14 +339,14 @@
         >>> uri.validate("www.python.org/foo/bar")
         Traceback (most recent call last):
         ...
-        ValidationError: ('Invalid uri', 'www.python.org/foo/bar')
+        InvalidURI: www.python.org/foo/bar
         """
 
         super(URI, self)._validate(value)
         if _isuri(value):
             return
 
-        raise ValidationError("Invalid uri", value)
+        raise InvalidURI, value
 
     def fromUnicode(self, value):
         """
@@ -360,7 +360,7 @@
         >>> uri.fromUnicode("http://www.python.org/ foo/bar")
         Traceback (most recent call last):
         ...
-        ValidationError: ('Invalid uri', 'http://www.python.org/ foo/bar')
+        InvalidURI: http://www.python.org/ foo/bar
         """
         v = str(value.strip())
         self.validate(v)
@@ -389,11 +389,11 @@
         >>> id.validate("zope.app.content/a")
         Traceback (most recent call last):
         ...
-        ValidationError: ('Invalid id', 'zope.app.content/a')
+        InvalidId: zope.app.content/a
         >>> id.validate("http://zope.app.content x y")
         Traceback (most recent call last):
         ...
-        ValidationError: ('Invalid id', 'http://zope.app.content x y')
+        InvalidId: http://zope.app.content x y
         """
         super(Id, self)._validate(value)
         if _isuri(value):
@@ -401,7 +401,7 @@
         if _isdotted(value) and "." in value:
             return
 
-        raise ValidationError("Invalid id", value)
+        raise InvalidId, value
 
     def fromUnicode(self, value):
         """
@@ -413,7 +413,7 @@
         >>> id.fromUnicode("http://www.python.org/ foo/bar")
         Traceback (most recent call last):
         ...
-        ValidationError: ('Invalid id', 'http://www.python.org/ foo/bar')
+        InvalidId: http://www.python.org/ foo/bar
         >>> id.fromUnicode("      \\n x.y.z \\n")
         'x.y.z'
 
@@ -475,7 +475,7 @@
         >>> dotted_name.validate("   a   ")
         Traceback (most recent call last):
         ...
-        ValidationError: ('invalid dotted name', '   a   ')
+        InvalidDottedName:    a   
 
         >>> dotted_name = DottedName(__name__='test', min_dots=1)
         >>> dotted_name.validate('a.b')
@@ -483,14 +483,14 @@
         >>> dotted_name.validate('a')
         Traceback (most recent call last):
         ...
-        ValidationError: ('too few dots; 1 required', 'a')
+        InvalidDottedName: ('too few dots; 1 required', 'a')
 
         >>> dotted_name = DottedName(__name__='test', max_dots=0)
         >>> dotted_name.validate('a')
         >>> dotted_name.validate('a.b')
         Traceback (most recent call last):
         ...
-        ValidationError: ('too many dots; no more than 0 allowed', 'a.b')
+        InvalidDottedName: ('too many dots; no more than 0 allowed', 'a.b')
 
         >>> dotted_name = DottedName(__name__='test', max_dots=2)
         >>> dotted_name.validate('a')
@@ -499,31 +499,31 @@
         >>> dotted_name.validate('a.b.c.d')
         Traceback (most recent call last):
         ...
-        ValidationError: ('too many dots; no more than 2 allowed', 'a.b.c.d')
+        InvalidDottedName: ('too many dots; no more than 2 allowed', 'a.b.c.d')
 
         >>> dotted_name = DottedName(__name__='test', max_dots=1, min_dots=1)
         >>> dotted_name.validate('a.b')
         >>> dotted_name.validate('a')
         Traceback (most recent call last):
         ...
-        ValidationError: ('too few dots; 1 required', 'a')
+        InvalidDottedName: ('too few dots; 1 required', 'a')
         >>> dotted_name.validate('a.b.c')
         Traceback (most recent call last):
         ...
-        ValidationError: ('too many dots; no more than 1 allowed', 'a.b.c')
+        InvalidDottedName: ('too many dots; no more than 1 allowed', 'a.b.c')
 
         """
         super(DottedName, self)._validate(value)
         if not _isdotted(value):
-            raise ValidationError("invalid dotted name", value)
+            raise InvalidDottedName(value)
         dots = value.count(".")
         if dots < self.min_dots:
-            raise ValidationError("too few dots; %d required" % self.min_dots,
-                                  value)
+            raise InvalidDottedName, \
+                  ("too few dots; %d required" % self.min_dots, value)
         if self.max_dots is not None and dots > self.max_dots:
-            raise ValidationError("too many dots; no more than %d allowed"
-                                  % self.max_dots,
-                                  value)
+            raise InvalidDottedName, \
+                  ("too many dots; no more than %d allowed" % self.max_dots,
+                   value)
 
     def fromUnicode(self, value):
         v = str(value.strip())


=== Zope3/src/zope/schema/vocabulary.py 1.20 => 1.21 ===
--- Zope3/src/zope/schema/vocabulary.py:1.20	Sat Feb 14 18:35:59 2004
+++ Zope3/src/zope/schema/vocabulary.py	Sun Apr 11 06:35:04 2004
@@ -18,7 +18,6 @@
 import copy
 
 from zope.interface.declarations import directlyProvides, implements
-from zope.schema import errornames
 from zope.schema import Field
 from zope.schema import MinMaxLen
 from zope.schema._bootstrapfields import ValidatedProperty
@@ -32,6 +31,8 @@
 from zope.schema.interfaces import ITokenizedTerm
 from zope.schema.interfaces import IFromUnicode
 
+from zope.schema.interfaces import ConstraintNotSatisfied
+
 class ContainerValidatedProperty(ValidatedProperty):
 
     def __get__(self, inst, type=None):
@@ -84,8 +85,7 @@
             # vocabulary without context
             return
         if value not in self.vocabulary:
-            raise ValidationError(errornames.ConstraintNotSatisfied,
-                                  value)
+            raise ConstraintNotSatisfied, value
     
     def fromUnicode(self, str):
         """
@@ -94,7 +94,7 @@
         >>> t.fromUnicode(u"baz")
         Traceback (most recent call last):
         ...
-        ValidationError: (u'Constraint not satisfied', u'baz')
+        ConstraintNotSatisfied: baz
         >>> t.fromUnicode(u"foo")
         u'foo'
         """
@@ -127,7 +127,7 @@
                 raise ValueError("can't validate value without vocabulary")
             for v in value:
                 if v not in vocab:
-                    raise ValidationError(errornames.ConstraintNotSatisfied, v)
+                    raise ConstraintNotSatisfied, v
         super(VocabularyMultiField, self)._validate(value)
 
 class UniqueElements(object):




More information about the Zope3-Checkins mailing list