[Zope3-checkins] CVS: Zope3/src/zope/schema - _bootstrapfields.py:1.1.2.2 _field.py:1.1.2.2

Guido van Rossum guido@python.org
Mon, 23 Dec 2002 15:38:04 -0500


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

Modified Files:
      Tag: NameGeddon-branch
	_bootstrapfields.py _field.py 
Log Message:
Buncha renames.  Schema tests run.

=== Zope3/src/zope/schema/_bootstrapfields.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.1.2.1	Mon Dec 23 14:33:12 2002
+++ Zope3/src/zope/schema/_bootstrapfields.py	Mon Dec 23 15:37:33 2002
@@ -16,11 +16,11 @@
 """
 __metaclass__ = type
 
-from zope.interface.element import Attribute
+from zope.interface import Attribute
 from zope.interface.implements import visitImplements
 
 from zope.schema.interfaces import StopValidation, ValidationError
-import zope.schema.errornames
+from zope.schema import errornames
 from zope.schema._schema import getFields
 
 class ValidatedProperty:
@@ -85,7 +85,7 @@
     def validate(self, value):
         if value is None:
             if self.required:
-                raise ValidationError(ErrorNames.RequiredMissing)
+                raise ValidationError(errornames.RequiredMissing)
         else:
             try:
                 self._validate(value)
@@ -114,10 +114,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 ValidationError(errornames.WrongType, value, self._type)
 
         if self.constraint is not None and not self.constraint(value):
-            raise ValidationError(ErrorNames.ConstraintNotSatisfied, value)
+            raise ValidationError(errornames.ConstraintNotSatisfied, value)
 
 
 class Container(Field):
@@ -129,7 +129,7 @@
             try:
                 iter(value)
             except:
-                raise ValidationError(ErrorNames.NotAContainer, value)
+                raise ValidationError(errornames.NotAContainer, value)
                 
                 
 class Iterable(Container):
@@ -141,7 +141,7 @@
         try:
             iter(value)
         except:
-            raise ValidationError(ErrorNames.NotAnIterator, value)
+            raise ValidationError(errornames.NotAnIterator, value)
 
 
 class Orderable(Field):
@@ -175,10 +175,10 @@
         super(Orderable, self)._validate(value)
         
         if self.min is not None and value < self.min:
-            raise ValidationError(ErrorNames.TooSmall, value, self.min)
+            raise ValidationError(errornames.TooSmall, value, self.min)
 
         if self.max is not None and value > self.max:
-            raise ValidationError(ErrorNames.TooBig, value, self.max)
+            raise ValidationError(errornames.TooBig, value, self.max)
 
 _int_types = int, long
 class MinMaxLen(Field):
@@ -194,10 +194,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 ValidationError(errornames.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 ValidationError(errornames.TooLong, value, self.max_length)
         
 
 class ValueSet(Field):
@@ -239,7 +239,7 @@
 
         if self.allowed_values:
             if not value in self.allowed_values:
-                raise ValidationError(ErrorNames.InvalidValue, value,
+                raise ValidationError(errornames.InvalidValue, value,
                                       self.allowed_values)
 
 


=== Zope3/src/zope/schema/_field.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/_field.py:1.1.2.1	Mon Dec 23 14:33:12 2002
+++ Zope3/src/zope/schema/_field.py	Mon Dec 23 15:37:33 2002
@@ -19,47 +19,51 @@
 from zope.interface.implements import implements
 
 from zope.schema.interfaces import ValidationError
-import zope.schema.errornames
+from zope.schema.errornames import WrongContainedType
+
+from zope.schema.interfaces import IField, IContainer, IIterable, IOrderable
+from zope.schema.interfaces import IMinMaxLen, IValueSet, IText, ITextLine
+from zope.schema.interfaces import IBool, IInt, IBytes, IBytesLine, IFloat
+from zope.schema.interfaces import IDatetime, ISequence, ITuple, IList, IDict
 
-import zope.schema.interfaces
 from zope.schema._bootstrapfields import Field, Container, Iterable, Orderable, MinMaxLen
 from zope.schema._bootstrapfields import ValueSet, Text, TextLine, Bool, Int
 from zope.schema.fieldproperty import FieldProperty
 from datetime import datetime
 
 # Fix up bootstrap field types
-Field.title       = FieldProperty(IField.IField['title'])
-Field.description = FieldProperty(IField.IField['description'])
-Field.required    = FieldProperty(IField.IField['required'])
-Field.readonly    = FieldProperty(IField.IField['readonly'])
+Field.title       = FieldProperty(IField['title'])
+Field.description = FieldProperty(IField['description'])
+Field.required    = FieldProperty(IField['required'])
+Field.readonly    = FieldProperty(IField['readonly'])
 # Default is already taken care of
-implements(Field, IField.IField)
+implements(Field, IField)
 
-implements(Container, IField.IContainer)
-implements(Iterable, IField.IIterable)
-implements(Orderable, IField.IOrderable)
-
-MinMaxLen.min_length = FieldProperty(IField.IMinMaxLen['min_length'])
-MinMaxLen.max_length = FieldProperty(IField.IMinMaxLen['max_length'])
-implements(MinMaxLen, IField.IMinMaxLen)
-
-implements(ValueSet, IField.IValueSet)
-
-implements(Text, IField.IText)
-implements(TextLine, IField.ITextLine)
-implements(Bool, IField.IBool)
-implements(Int, IField.IInt)
+implements(Container, IContainer)
+implements(Iterable, IIterable)
+implements(Orderable, IOrderable)
+
+MinMaxLen.min_length = FieldProperty(IMinMaxLen['min_length'])
+MinMaxLen.max_length = FieldProperty(IMinMaxLen['max_length'])
+implements(MinMaxLen, IMinMaxLen)
+
+implements(ValueSet, IValueSet)
+
+implements(Text, IText)
+implements(TextLine, ITextLine)
+implements(Bool, IBool)
+implements(Int, IInt)
             
 class Bytes(MinMaxLen, ValueSet):
-    __doc__ = IField.IBytes.__doc__
-    __implements__ = IField.IBytes
+    __doc__ = IBytes.__doc__
+    __implements__ = IBytes
     
     _type = str
 
 class BytesLine(Bytes):
     """A Text field with no newlines."""
 
-    __implements__ = IField.IBytesLine
+    __implements__ = IBytesLine
 
     def constraint(self, value):
         # XXX we should probably use a more general definition of newlines
@@ -67,13 +71,13 @@
     
 
 class Float(ValueSet, Orderable):
-    __doc__ = IField.IFloat.__doc__
-    __implements__ = IField.IFloat
+    __doc__ = IFloat.__doc__
+    __implements__ = IFloat
     _type = float
 
 class Datetime(ValueSet, Orderable):
-    __doc__ = IField.IDatetime.__doc__
-    __implements__ = IField.IDatetime
+    __doc__ = IDatetime.__doc__
+    __implements__ = IDatetime
     _type = datetime
 
 def _validate_sequence(value_types, value, errors=None):
@@ -103,8 +107,8 @@
     
 
 class Sequence(MinMaxLen, Iterable):
-    __doc__ = IField.ISequence.__doc__
-    value_types = FieldProperty(IField.ISequence['value_types'])
+    __doc__ = ISequence.__doc__
+    value_types = FieldProperty(ISequence['value_types'])
 
     def __init__(self, value_types=None, **kw):
         super(Sequence, self).__init__(**kw)
@@ -115,27 +119,27 @@
         try:
             errors = _validate_sequence(self.value_types, value)
             if errors:
-                raise ValidationError(ErrorNames.WrongContainedType, errors)
+                raise ValidationError(WrongContainedType, errors)
                 
         finally:
             errors = None
 
 class Tuple(Sequence):
     """A field representing a Tuple."""
-    __implements__ = IField.ITuple
+    __implements__ = ITuple
     _type = tuple
 
 class List(Sequence):
     """A field representing a List."""
-    __implements__ = IField.IList
+    __implements__ = IList
     _type = list
 
 class Dict(MinMaxLen, Iterable):
     """A field representing a Dict."""
-    __implements__ = IField.IDict
+    __implements__ = IDict
     _type = dict
-    key_types   = FieldProperty(IField.IDict['key_types'])
-    value_types = FieldProperty(IField.IDict['value_types'])
+    key_types   = FieldProperty(IDict['key_types'])
+    value_types = FieldProperty(IDict['value_types'])
 
     def __init__(self, key_types=None, value_types=None, **kw):
         super(Dict, self).__init__(**kw)
@@ -152,8 +156,7 @@
             errors = _validate_sequence(self.key_types, value, errors)
 
             if errors:
-                raise ValidationError(ErrorNames.WrongContainedType, errors)
+                raise ValidationError(WrongContainedType, errors)
                 
         finally:
             errors = None
-