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

Steve Alexander steve@cat-box.net
Fri, 28 Feb 2003 09:23:23 -0500


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

Modified Files:
	_bootstrapfields.py 
Log Message:
Removed a bare except: and replaced it with a much nicer try: finally:
Added some explanatory comments for some code I didn't understand at first.
Removed support for the lack of True and False constants in python 2.2.0.



=== Zope3/src/zope/schema/_bootstrapfields.py 1.5 => 1.6 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.5	Fri Jan 24 21:52:27 2003
+++ Zope3/src/zope/schema/_bootstrapfields.py	Fri Feb 28 09:23:23 2003
@@ -203,21 +203,23 @@
 class ValueSet(Field):
 
     def allowed_values(self, values):
-        # Reset current value so it doesn't hose validation
+        # 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
-
-        for value in values:
-
-            try:
+        try:
+            for value in values:
                 self.validate(value)
-            except:
-                # restore the old value
-                self.allowed_values = old_allowed
-                raise
+        finally:
+            # restore the old value
+            self.allowed_values = old_allowed
 
     allowed_values = ValidatedProperty('allowed_values', allowed_values)
 
@@ -258,16 +260,7 @@
 
 class Bool(Field):
     """A field representing a Bool."""
-
-    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")
-    except NameError:
-        # Pre booleans
-        _type = int
-    else:
-        _type = bool
+    _type = type(True)
 
 class Int(ValueSet, Orderable):
     """A field representing an Integer."""