[Zope3-checkins] CVS: Zope3/src/zope/schema - __init__.py:1.17 _bootstrapfields.py:1.26 _field.py:1.27 interfaces.py:1.38

Philipp von Weitershausen philikon at philikon.de
Fri Jan 16 08:38:51 EST 2004


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

Modified Files:
	__init__.py _bootstrapfields.py _field.py interfaces.py 
Log Message:
Changes to the schema package and the widget machinery (see
http://mail.zope.org/pipermail/zope3-dev/2004-January/009265.html):

- Widgets requiring key_type and/or value_type arguments will now check
  whether they implement IField. Before, anything was accepted although
  a field instance was implied. A key_type/value_type of None implies no
  validation of the key/value.

- Basic fields like TextLine, Int, Float, Date, and Datetime are not
  enumerated fields anymore. There are separate Enumerated* fields for
  that purpose now. Extra widgets for that functionality were added
  and configured.


=== Zope3/src/zope/schema/__init__.py 1.16 => 1.17 ===
--- Zope3/src/zope/schema/__init__.py:1.16	Wed Dec 17 05:48:51 2003
+++ Zope3/src/zope/schema/__init__.py	Fri Jan 16 08:38:20 2004
@@ -24,11 +24,8 @@
 from zope.schema._field import Object, URI, Id, DottedName
 from zope.schema._field import EnumeratedTextLine, EnumeratedInt
 from zope.schema._field import EnumeratedDatetime, EnumeratedFloat
-from zope.schema._field import InterfaceField
+from zope.schema._field import EnumeratedDate, InterfaceField
 from zope.schema._schema import getFields, getFieldsInOrder
 from zope.schema._schema import getFieldNames, getFieldNamesInOrder
 from zope.schema.accessors import accessors
 from zope.schema.interfaces import ValidationError
-
-# XXX backward compatibility; to be removed within a week
-ValueSet = Enumerated


=== Zope3/src/zope/schema/_bootstrapfields.py 1.25 => 1.26 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.25	Mon Oct 20 12:11:46 2003
+++ Zope3/src/zope/schema/_bootstrapfields.py	Fri Jan 16 08:38:20 2004
@@ -179,7 +179,6 @@
         return not self.__eq__(other)
 
     def _validate(self, value):
-
         if self._type is not None and not isinstance(value, self._type):
             raise ValidationError(errornames.WrongType, value, self._type)
 
@@ -334,19 +333,13 @@
                 raise ValidationError(errornames.InvalidValue, value,
                                       self.allowed_values)
 
-class Text(Enumerated, MinMaxLen, Field):
+class Text(MinMaxLen, Field):
     """A field containing text used for human discourse."""
     _type = unicode
 
     implements(IFromUnicode)
 
     def __init__(self, *args, **kw):
-        if (  kw.get("allowed_values") is not None
-              and self.__class__ in (Text, TextLine)):
-            clsname = self.__class__.__name__
-            warnings.warn("Support for allowed_values will be removed from %s;"
-                          " use Enumerated%s instead" % (clsname, clsname),
-                          DeprecationWarning, stacklevel=2)
         super(Text, self).__init__(*args, **kw)
 
     def fromUnicode(self, str):
@@ -372,7 +365,7 @@
     def constraint(self, value):
         return '\n' not in value and '\r' not in value
 
-class EnumeratedTextLine(TextLine):
+class EnumeratedTextLine(Enumerated, TextLine):
     """TextLine with a value from a list of allowed values."""
 
 class Password(TextLine):
@@ -399,19 +392,13 @@
                 value = bool(value)
             Field.set(self, object, value)
 
-class Int(Enumerated, Orderable, Field):
+class Int(Orderable, Field):
     """A field representing an Integer."""
     _type = int, long
 
     implements(IFromUnicode)
 
     def __init__(self, *args, **kw):
-        if (  kw.get("allowed_values") is not None
-              and self.__class__ is Int):
-            clsname = self.__class__.__name__
-            warnings.warn("Support for allowed_values will be removed from %s;"
-                          " use Enumerated%s instead" % (clsname, clsname),
-                          DeprecationWarning, stacklevel=2)
         super(Int, self).__init__(*args, **kw)
 
     def fromUnicode(self, str):
@@ -428,5 +415,5 @@
         self.validate(v)
         return v
 
-class EnumeratedInt(Int):
+class EnumeratedInt(Enumerated, Int):
     """A field representing one of a selected set of Integers."""


=== Zope3/src/zope/schema/_field.py 1.26 => 1.27 ===
--- Zope3/src/zope/schema/_field.py:1.26	Wed Dec 17 05:48:51 2003
+++ Zope3/src/zope/schema/_field.py	Fri Jan 16 08:38:20 2004
@@ -34,11 +34,10 @@
 from zope.schema.interfaces import IInterfaceField
 from zope.schema.interfaces import IBool, IInt, IBytes, IASCII, IBytesLine, IFloat
 from zope.schema.interfaces import IDatetime, ISequence, ITuple, IList, IDict
-from zope.schema.interfaces import IPassword, IObject, IDate
+from zope.schema.interfaces import IPassword, IObject, IDate, IEnumeratedDate
 from zope.schema.interfaces import IEnumeratedDatetime, IEnumeratedTextLine
 from zope.schema.interfaces import IEnumeratedInt, IEnumeratedFloat
-from zope.schema.interfaces import IURI, IId
-from zope.schema.interfaces import IFromUnicode
+from zope.schema.interfaces import IURI, IId, IFromUnicode
 
 from zope.schema._bootstrapfields import Field, Container, Iterable, Orderable
 from zope.schema._bootstrapfields import MinMaxLen, Enumerated
@@ -71,7 +70,7 @@
     implements(ISourceText)
     _type = unicode
 
-class Bytes(Enumerated, MinMaxLen, Field):
+class Bytes(MinMaxLen, Field):
     __doc__ = IBytes.__doc__
     implements(IBytes, IFromUnicode)
 
@@ -96,7 +95,7 @@
 class ASCII(Bytes):
     __doc__ = IASCII.__doc__
     implements(IASCII)
-    
+
 
 class BytesLine(Bytes):
     """A Text field with no newlines."""
@@ -108,18 +107,12 @@
         return '\n' not in value
 
 
-class Float(Enumerated, Orderable, Field):
+class Float(Orderable, Field):
     __doc__ = IFloat.__doc__
     implements(IFloat, IFromUnicode)
     _type = float
 
     def __init__(self, *args, **kw):
-        if (  kw.get("allowed_values") is not None
-              and self.__class__ is Float):
-            clsname = self.__class__.__name__
-            warnings.warn("Support for allowed_values will be removed from %s;"
-                          " use Enumerated%s instead" % (clsname, clsname),
-                          DeprecationWarning, stacklevel=2)
         super(Float, self).__init__(*args, **kw)
 
     def fromUnicode(self, u):
@@ -136,33 +129,31 @@
         self.validate(v)
         return v
 
-class EnumeratedFloat(Float):
+class EnumeratedFloat(Enumerated, Float):
     __doc__ = IEnumeratedFloat.__doc__
     implements(IEnumeratedFloat)
 
-class Datetime(Enumerated, Orderable, Field):
+class Datetime(Orderable, Field):
     __doc__ = IDatetime.__doc__
     implements(IDatetime)
     _type = datetime
 
     def __init__(self, *args, **kw):
-        if (  kw.get("allowed_values") is not None
-              and self.__class__ is Datetime):
-            clsname = self.__class__.__name__
-            warnings.warn("Support for allowed_values will be removed from %s;"
-                          " use Enumerated%s instead" % (clsname, clsname),
-                          DeprecationWarning, stacklevel=2)
         super(Datetime, self).__init__(*args, **kw)
 
-class EnumeratedDatetime(Datetime):
+class EnumeratedDatetime(Enumerated, Datetime):
     __doc__ = IEnumeratedDatetime.__doc__
     implements(IEnumeratedDatetime)
 
-class Date(Enumerated, Orderable, Field):
+class Date(Orderable, Field):
     __doc__ = IDate.__doc__
     implements(IDate)
     _type = date
 
+class EnumeratedDate(Enumerated, Date):
+    __doc__ = IEnumeratedDate.__doc__
+    implements(IEnumeratedDate)
+
 class InterfaceField(Field):
     __doc__ = IInterfaceField.__doc__
     implements(IInterfaceField)
@@ -204,7 +195,9 @@
 
     def __init__(self, value_type=None, **kw):
         super(Sequence, self).__init__(**kw)
-        # XXX reject value_type of None?
+        # whine if value_type is not a field
+        if value_type is not None and not IField.isImplementedBy(value_type):
+            raise ValueError, "'value_type' must be field instance."
         self.value_type = value_type
 
     def _validate(self, value):
@@ -279,7 +272,11 @@
 
     def __init__(self, key_type=None, value_type=None, **kw):
         super(Dict, self).__init__(**kw)
-        # XXX reject key_type, value_type of None?
+        # whine if key_type or value_type is not a field
+        if key_type is not None and not IField.isImplementedBy(key_type):
+            raise ValueError, "'key_type' must be field instance."
+        if value_type is not None and not IField.isImplementedBy(value_type):
+            raise ValueError, "'value_type' must be field instance."
         self.key_type = key_type
         self.value_type = value_type
 


=== Zope3/src/zope/schema/interfaces.py 1.37 => 1.38 ===
--- Zope3/src/zope/schema/interfaces.py:1.37	Tue Jan  6 10:44:51 2004
+++ Zope3/src/zope/schema/interfaces.py	Fri Jan 16 08:38:20 2004
@@ -241,8 +241,6 @@
         restictions."""),
         required=False)
 
-IValueSet = IEnumerated
-
 class IInterfaceField(IField):
     u"""Fields with a value that is an interface (implementing
     zope.interface.Interface)."""
@@ -256,15 +254,13 @@
                         field value""")
         )
 
-class IBytes(IMinMaxLen, IEnumerated, IIterable, IField):
-    # XXX IEnumerated will be removed in the future.
+class IBytes(IMinMaxLen, IIterable, IField):
     u"""Field containing a byte string (like the python str).
 
     The value might be constrained to be with length limits.
     """
 
-class IASCII(IMinMaxLen, IEnumerated, IIterable, IField):
-    # XXX IEnumerated will be removed in the future.
+class IASCII(IMinMaxLen, IIterable, IField):
     u"""Field containing a byte string (like the python str).
 
     The value might be constrained to be with length limits.
@@ -273,9 +269,7 @@
 class IBytesLine(IBytes):
     u"""Field containing a byte string without newlines."""
 
-class IText(IMinMaxLen, IEnumerated, IIterable, IField):
-    # XXX IEnumerated doesn't make sense for multi-line strings, so will
-    # be removed in the future.
+class IText(IMinMaxLen, IIterable, IField):
     u"""Field containing a unicode string."""
 
 class ISourceText(IText):
@@ -293,9 +287,7 @@
 class IPassword(ITextLine):
     u"""Field containing a unicode string without newlines that is a password."""
 
-class IInt(IMinMax, IEnumerated, IField):
-    # XXX IEnumerated will be removed; use IEnumeratedInt instead if you
-    # need the IEnumerated interface.
+class IInt(IMinMax, IField):
     u"""Field containing an Integer Value."""
 
     min = Int(
@@ -322,9 +314,7 @@
     The value may be constrained to an element of a specified list.
     """
 
-class IFloat(IMinMax, IEnumerated, IField):
-    # XXX IEnumerated will be removed; use IEnumeratedFloat instead if you
-    # need the IEnumerated interface.
+class IFloat(IMinMax, IField):
     u"""Field containing a Float."""
 
 class IEnumeratedFloat(IEnumerated, IFloat):
@@ -333,9 +323,7 @@
     The value may be constrained to an element of a specified list.
     """
 
-class IDatetime(IMinMax, IEnumerated, IField):
-    # XXX IEnumerated will be removed; use IEnumeratedDatetime instead
-    # if you need the IEnumerated interface.
+class IDatetime(IMinMax, IField):
     u"""Field containing a DateTime."""
 
 class IEnumeratedDatetime(IEnumerated, IDatetime):
@@ -344,8 +332,14 @@
     The value may be constrained to an element of a specified list.
     """
 
-class IDate(IMinMax, IEnumerated, IField):
+class IDate(IMinMax, IField):
     u"""Field containing a date."""
+
+class IEnumeratedDate(IEnumerated, IDate):
+    u"""Field containing a date.
+
+    The value may be constrained to an element of a specified list.
+    """
 
 def _is_field(value):
     if not IField.isImplementedBy(value):




More information about the Zope3-Checkins mailing list