[Zope3-checkins] CVS: Zope3/lib/python/Zope/Schema - _bootstrapFields.py:1.6
Martijn Faassen
m.faassen@vet.uu.nl
Wed, 11 Dec 2002 09:49:07 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Schema
In directory cvs.zope.org:/tmp/cvs-serv18264
Modified Files:
_bootstrapFields.py
Log Message:
Added the ability to compare fields for equality. Also got rid of an
'L' in 'order'; if we ever will have more than maxint fields
we'll worry about that then (and python will automatically upgrade ints
anyway, right?).
=== Zope3/lib/python/Zope/Schema/_bootstrapFields.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/Schema/_bootstrapFields.py:1.5 Thu Dec 5 08:27:06 2002
+++ Zope3/lib/python/Zope/Schema/_bootstrapFields.py Wed Dec 11 09:49:06 2002
@@ -17,8 +17,11 @@
__metaclass__ = type
from Interface.Attribute import Attribute
+from Interface.Implements import visitImplements
+
from Exceptions import StopValidation, ValidationError
import ErrorNames
+from _Schema import getFields
class ValidatedProperty:
@@ -38,7 +41,7 @@
# Type restrictions, if any
_type = None
- order = 0l
+ order = 0
context = None
constraint = None
@@ -88,7 +91,26 @@
self._validate(value)
except StopValidation:
pass
-
+
+ def __eq__(self, other):
+ # should be the same type
+ if type(self) != type(other):
+ return False
+ # should have the same properties
+ names = {} # used as set of property names, ignoring values
+ visitImplements(self.__implements__, self,
+ lambda interface: names.update(getFields(interface)))
+ # order will be different always, don't compare it
+ if 'order' in names:
+ del names['order']
+ for name in names:
+ if getattr(self, name) != getattr(other, name):
+ return False
+ return True
+
+ 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):