[Zope3-checkins] CVS: Zope3/src/zope/schema - __init__.py:1.1.2.2 _bootstrapfields.py:1.1.2.3 _field.py:1.1.2.3 _schema.py:1.1.2.2 errornames.py:1.1.2.2 fieldproperty.py:1.1.2.2 interfaces.py:1.1.2.2
Tim Peters
tim.one@comcast.net
Tue, 24 Dec 2002 21:21:47 -0500
Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv19240/src/zope/schema
Modified Files:
Tag: NameGeddon-branch
__init__.py _bootstrapfields.py _field.py _schema.py
errornames.py fieldproperty.py interfaces.py
Log Message:
Whitespace normalization, via Python's Tools/scripts/reindent.py. The
files are fixed-points of that script now. Fixed a few cases where
code relied on significant trailing whitespace (ouch).
=== Zope3/src/zope/schema/__init__.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/__init__.py:1.1.2.1 Mon Dec 23 14:33:12 2002
+++ Zope3/src/zope/schema/__init__.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""Schema package constructor
=== Zope3/src/zope/schema/_bootstrapfields.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.1.2.2 Mon Dec 23 15:37:33 2002
+++ Zope3/src/zope/schema/_bootstrapfields.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""
$Id$
@@ -36,7 +36,7 @@
else:
inst.validate(value)
inst.__dict__[name] = value
-
+
class Field(Attribute):
# Type restrictions, if any
@@ -46,7 +46,7 @@
constraint = None
default = ValidatedProperty('default')
-
+
def __init__(self, __name__='', __doc__='',
title=u'', description=u'',
required=True, readonly=False, constraint=None, default=None,
@@ -81,7 +81,7 @@
clone.__dict__.update(self.__dict__)
clone.context = object
return clone
-
+
def validate(self, value):
if value is None:
if self.required:
@@ -110,7 +110,7 @@
def __ne__(self, other):
return not self.__eq__(other)
-
+
def _validate(self, value):
if self._type is not None and not isinstance(value, self._type):
@@ -130,8 +130,8 @@
iter(value)
except:
raise ValidationError(errornames.NotAContainer, value)
-
-
+
+
class Iterable(Container):
def _validate(self, value):
@@ -169,11 +169,11 @@
# We've taken over setting default so it can be limited by min
# and max.
self.default = default
-
+
def _validate(self, value):
super(Orderable, self)._validate(value)
-
+
if self.min is not None and value < self.min:
raise ValidationError(errornames.TooSmall, value, self.min)
@@ -198,7 +198,7 @@
if self.max_length is not None and len(value) > self.max_length:
raise ValidationError(errornames.TooLong, value, self.max_length)
-
+
class ValueSet(Field):
@@ -206,16 +206,16 @@
# Reset current value so it doesn't hose validation
if not values:
return
-
+
old_allowed = getattr(self, 'allowed_values', None)
self.allowed_values = None
for value in values:
-
+
try:
self.validate(value)
except:
- # restore the old value
+ # restore the old value
self.allowed_values = old_allowed
raise
@@ -246,7 +246,7 @@
class Text(MinMaxLen, ValueSet):
"""A field containing text used for human discourse."""
_type = unicode
-
+
class TextLine(Text):
"""A Text field with no newlines."""
@@ -254,7 +254,7 @@
def constraint(self, value):
# XXX we should probably use a more general definition of newlines
return '\n' not in value
-
+
class Bool(Field):
"""A field representing a Bool."""
@@ -262,7 +262,7 @@
try:
if type(True) is int:
# If we have True and it's an int, then pretend we're 2.2.0.
- raise NameError("True")
+ raise NameError("True")
except NameError:
# Pre booleans
_type = int
=== Zope3/src/zope/schema/_field.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/schema/_field.py:1.1.2.2 Mon Dec 23 15:37:33 2002
+++ Zope3/src/zope/schema/_field.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""
$Id$
@@ -53,11 +53,11 @@
implements(TextLine, ITextLine)
implements(Bool, IBool)
implements(Int, IInt)
-
+
class Bytes(MinMaxLen, ValueSet):
__doc__ = IBytes.__doc__
__implements__ = IBytes
-
+
_type = str
class BytesLine(Bytes):
@@ -68,7 +68,7 @@
def constraint(self, value):
# XXX we should probably use a more general definition of newlines
return '\n' not in value
-
+
class Float(ValueSet, Orderable):
__doc__ = IFloat.__doc__
@@ -83,7 +83,7 @@
def _validate_sequence(value_types, value, errors=None):
if errors is None:
errors = []
-
+
if value_types is None:
return errors
@@ -104,7 +104,7 @@
errors.append(error)
return errors
-
+
class Sequence(MinMaxLen, Iterable):
__doc__ = ISequence.__doc__
@@ -120,7 +120,7 @@
errors = _validate_sequence(self.value_types, value)
if errors:
raise ValidationError(WrongContainedType, errors)
-
+
finally:
errors = None
@@ -157,6 +157,6 @@
if errors:
raise ValidationError(WrongContainedType, errors)
-
+
finally:
errors = None
=== Zope3/src/zope/schema/_schema.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/_schema.py:1.1.2.1 Mon Dec 23 14:33:13 2002
+++ Zope3/src/zope/schema/_schema.py Tue Dec 24 21:21:16 2002
@@ -2,21 +2,21 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""
$Id$
"""
from zope.interface import Interface
from zope.schema.interfaces import ValidationError, ValidationErrorsAll
-
+
def getFields(schema):
"""Get all fields on a schema.
"""
@@ -65,4 +65,3 @@
errors.append((name, e))
if errors:
raise ValidationErrorsAll, errors
-
=== Zope3/src/zope/schema/errornames.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/errornames.py:1.1.2.1 Mon Dec 23 14:33:13 2002
+++ Zope3/src/zope/schema/errornames.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""Common Schema Error Names
=== Zope3/src/zope/schema/fieldproperty.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/fieldproperty.py:1.1.2.1 Mon Dec 23 14:33:13 2002
+++ Zope3/src/zope/schema/fieldproperty.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""
$Id$
@@ -27,7 +27,7 @@
Note that FieldProperties cannot be used with slots. They can only
be used for attributes stored in instance dictionaries.
-
+
"""
def __init__(self, field, name=None):
@@ -59,4 +59,3 @@
return getattr(self.__field, name)
__doc__ = FieldProperty.__doc__ + __doc__
-
=== Zope3/src/zope/schema/interfaces.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/schema/interfaces.py:1.1.2.1 Mon Dec 23 14:33:13 2002
+++ Zope3/src/zope/schema/interfaces.py Tue Dec 24 21:21:16 2002
@@ -2,14 +2,14 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""Validation Exceptions
@@ -75,18 +75,18 @@
class IField(Interface):
"""Basic Schema Field Interface.
- Fields are used for Interface specifications. They at least provide
+ Fields are used for Interface specifications. They at least provide
a title, description and a default value. You can also
- specify if they are required and/or readonly.
+ specify if they are required and/or readonly.
+
+ The Field Interface is also used for validation and specifying
+ constraints.
- The Field Interface is also used for validation and specifying
- constraints.
-
We want to make it possible for a IField to not only work
- on its value but also on the object this value is bound to.
+ on its value but also on the object this value is bound to.
This enables a Field implementation to perform validation
- against an object which also marks a certain place.
-
+ against an object which also marks a certain place.
+
Note that many fields need information about the object
containing a field. For example, when validating a value to be
set as an object attribute, it may be necessary for the field to
@@ -113,22 +113,22 @@
Options 2 and 3 allow us to use properties, but require an extra
binding step.
-
+
Option 1 and 3 will require a significant refactoring.
Option 2 requires us to make field methods, or at least the
validate method into ContextMethods, which is a bit intrusive.
- For now, we will use option 3.
+ For now, we will use option 3.
"""
def bind(object):
- """return a copy of this field which is bound to an object.
+ """return a copy of this field which is bound to an object.
The copy of the Field will have the 'context' attribute set
- to 'object'. This way a Field can implement more complex
- checks involving the object and its location.
+ to 'object'. This way a Field can implement more complex
+ checks involving the object and its location.
Many fields don't need to be bound. Only fields that condition
validation or properties on an object containing the field
@@ -141,14 +141,14 @@
default=u"",
required=False,
)
-
+
description = Text(
title=u"Description",
description=u"A description of the field",
default=u"",
required=False,
)
-
+
required = Bool(
title=u"Required",
description=(
@@ -168,11 +168,11 @@
)
def constraint(value):
- u"""check a customized contraint on the value.
+ u"""check a customized contraint on the value.
- You can implement this method with your Field to
+ You can implement this method with your Field to
require a certain constraint. This relaxes the need
- to inherit/subclass a Field you to add a simple contraint.
+ to inherit/subclass a Field you to add a simple contraint.
Returns true if the given value is within the Field's contraint.
"""
@@ -181,7 +181,7 @@
Returns nothing but raises an error if the value is invalid.
It checks everything specific to a Field and also checks
- with the additional constraint.
+ with the additional constraint.
"""
order = Int(
@@ -202,30 +202,30 @@
class IIterable(IField):
u"""Fields with a value that can be iterated over.
- The value needs to follow the python __iter__ protocol.
+ The value needs to follow the python __iter__ protocol.
"""
class IContainer(IField):
- u"""Fields whose value allows an 'x in value' check.
+ u"""Fields whose value allows an 'x in value' check.
- The Value needs to have a conventional __contains__ method.
+ The Value needs to have a conventional __contains__ method.
"""
class IOrderable(IField):
u"""a Field requiring its value to be orderable.
- The value needs to have a conventional __cmp__ method.
+ The value needs to have a conventional __cmp__ method.
"""
class ILen(IField):
- u"""a Field requiring its value to have a length.
+ u"""a Field requiring its value to have a length.
The value needs to have a conventional __len__ method.
"""
class IMinMax(IOrderable):
- u"""a Field requiring its value to be between min and max.
-
+ u"""a Field requiring its value to be between min and max.
+
This also means that the value needs to support the IOrderable interface.
"""
@@ -240,16 +240,16 @@
required=False,
default=None
)
-
+
class IMinMaxLen(ILen):
u"""a Field requiring the length of its value to be within a range"""
-
+
min_length = Int(
title=u"Minimum length",
description=u"""\
- Value after whitespace processing cannot have less than
- min_length characters. If min_length is None, there is
+ Value after whitespace processing cannot have less than
+ min_length characters. If min_length is None, there is
no minimum.
""",
required=False,
@@ -268,7 +268,7 @@
class IValueSet(IField):
u"""Field whose value is contained in a predefined set"""
-
+
allowed_values = Container(
title=u"Allowed Values",
description=u"""\
@@ -276,15 +276,15 @@
If the list is empty, then there are no further
restictions.""",
required=False)
-
+
class IBool(IField):
u"""a Boolean Field."""
class IBytes(IMinMaxLen, IValueSet, IIterable):
u"""a Field containing a byte string (like the python str).
- The value might be contrained to be with length limits, or
- be within a set of values.
+ The value might be contrained to be with length limits, or
+ be within a set of values.
"""
class IBytesLine(IBytes):
@@ -295,13 +295,13 @@
class ITextLine(IText):
u"""a Field containing a unicode string without newlines."""
-
+
class IInt(IMinMax, IValueSet):
u"""a Field containing an Integer Value."""
-
+
class IFloat(IMinMax, IValueSet):
u"""a Field containing a Float."""
-
+
class IDatetime(IMinMax, IValueSet):
u"""a Field containing a DateTime."""