[Zope3-checkins] CVS: Zope3/src/zope/schema -
_bootstrapfields.py:1.29
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Apr 24 19:20:42 EDT 2004
Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv30910/src/zope/schema
Modified Files:
_bootstrapfields.py
Log Message:
Remove Enumerated* code.
=== Zope3/src/zope/schema/_bootstrapfields.py 1.28 => 1.29 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.28 Sun Apr 11 06:35:04 2004
+++ Zope3/src/zope/schema/_bootstrapfields.py Sat Apr 24 19:20:42 2004
@@ -14,10 +14,6 @@
"""
$Id$
"""
-__metaclass__ = type
-
-import warnings
-
from zope.interface import Attribute, providedBy, implements
from zope.schema._bootstrapinterfaces import StopValidation
from zope.schema._bootstrapinterfaces import IFromUnicode
@@ -30,7 +26,7 @@
from zope.schema._schema import getFields
-class ValidatedProperty:
+class ValidatedProperty(object):
def __init__(self, name, check=None):
self._info = name, check
@@ -230,7 +226,7 @@
raise NotAnIterator(value)
-class Orderable:
+class Orderable(object):
"""Values of ordered fields can be sorted.
They can be restricted to a range of values.
@@ -269,7 +265,7 @@
raise TooBig(value, self.max)
-class MinMaxLen:
+class MinMaxLen(object):
"""Expresses constraints on the length of a field.
MinMaxLen is a mixin used in combination with Field.
@@ -291,53 +287,6 @@
if self.max_length is not None and len(value) > self.max_length:
raise TooLong(value, self.max_length)
-
-class Enumerated:
- """Enumerated fields can have a value found in a constant set of
- values given by the field definition.
-
- Enumerated is a mixin used in combination with Field.
- """
-
- def __init__(self, allowed_values=None, default=None, **kw):
- # Set allowed_values to None so that we can validate if
- # one of the super methods invoke validation.
- self.__dict__['allowed_values'] = None
- super(Enumerated, self).__init__(**kw)
- if allowed_values is not None:
- self.allowed_values = allowed_values
-
- # We've taken over setting default so it can be limited by min
- # and max.
- self.default = default
-
- def allowed_values(self, values):
- # This method checks that each of the given allowed values
- # are valid potential values.
-
- if not values:
- return
-
- # Reset current value of allowed_values to not constrain allowed
- # values. If we didn't do this, we'd only be able to allow a subset
- # of the values currently allowed.
- old_allowed = getattr(self, 'allowed_values', None)
- self.allowed_values = None
- try:
- for value in values:
- self.validate(value)
- finally:
- # restore the old value
- self.allowed_values = old_allowed
-
- allowed_values = ValidatedProperty('allowed_values', allowed_values)
-
- def _validate(self, value):
- super(Enumerated, self)._validate(value)
- if self.allowed_values:
- if not value in self.allowed_values:
- raise InvalidValue(value, self.allowed_values)
-
class Text(MinMaxLen, Field):
"""A field containing text used for human discourse."""
_type = unicode
@@ -370,9 +319,6 @@
def constraint(self, value):
return '\n' not in value and '\r' not in value
-class EnumeratedTextLine(Enumerated, TextLine):
- """TextLine with a value from a list of allowed values."""
-
class Password(TextLine):
"""A text field containing a text used as a password."""
@@ -419,6 +365,3 @@
v = int(str)
self.validate(v)
return v
-
-class EnumeratedInt(Enumerated, Int):
- """A field representing one of a selected set of Integers."""
More information about the Zope3-Checkins
mailing list