quixote/form widget.py,1.31,1.32

David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]>
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Update of /home/cvs/quixote/form
In directory hewson:/tmp/cvs-serv19463

Modified Files:
	widget.py 
Log Message:
Restore python 2.1 compatibility.  Don't use builtin types.


Index: widget.py
===================================================================
RCS file: /home/cvs/quixote/form/widget.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- widget.py	28 Oct 2002 16:22:25 -0000	1.31
+++ widget.py	28 Oct 2002 22:54:55 -0000	1.32
@@ -8,6 +8,7 @@
 
 __revision__ = "$Id$"
 
+from types import FloatType, IntType, ListType, StringType, TupleType 
 from quixote import get_request
 from quixote.html import htmltext, htmlescape, htmltag, ValuelessAttr
 
@@ -76,7 +77,7 @@
     def parse (self, request):
         """parse(request) -> any"""
         value = request.form.get(self.name)
-        if type(value) is str and value.strip():
+        if type(value) is StringType and value.strip():
             self.value = value
         else:
             self.value = None
@@ -256,7 +257,7 @@
 
 
     def set_allowed_values (self, allowed_values, descriptions, sort=0):
-        assert type(allowed_values) in (list, tuple), (
+        assert type(allowed_values) in (ListType, TupleType), (
             "allowed_values for '%s' not a list or tuple: got %r" %
             (self.name, allowed_values))
         self.allowed_values = allowed_values
@@ -269,7 +270,7 @@
                     v = str(v)
                 self.descriptions.append(v)
         else:
-            assert type(descriptions) in (list, tuple), (
+            assert type(descriptions) in (ListType, TupleType), (
                 "descriptions for '%s' not a list or tuple: got %r" %
                 (self.name, descriptions))
             assert len(self.allowed_values) == len(descriptions), (
@@ -415,7 +416,7 @@
     def set_value (self, value):
         if value in self.allowed_values:
             self.value = [value]
-        elif type(value) in (list, tuple):
+        elif type(value) in (ListType, TupleType):
             self.value = [val for val in value
                           if val in self.allowed_values] or None
         else:
@@ -423,7 +424,7 @@
 
 
     def is_selected (self, value):
-        if type(self.value) in (list, tuple) and value in self.value:
+        if type(self.value) in (ListType, TupleType) and value in self.value:
             return 1
         return value == self.value
 
@@ -521,7 +522,8 @@
     # these class attributes:
     type_object = None                  # eg. int, float
     type_error = None                   # human-readable error message
-
+    type_converter = None               # eg. int(), float()
+    
     def __init__ (self, name,
                   value=None,
                   size=None, maxlength=None):
@@ -532,19 +534,17 @@
                                                   value))
         StringWidget.__init__(self, name, value, size, maxlength)
 
-
     def set_value (self, value):
         if value is None:
             self.value = None
         else:
             self.value = str(value)
 
-
     def parse (self, request):
         value = StringWidget.parse(self, request)
         if value:
             try:
-                self.value = self.type_object(value)
+                self.value = self.type_converter(value)
             except ValueError:
                 raise FormValueError, self.type_error
         return self.value
@@ -557,7 +557,8 @@
     """
 
     widget_type = "float"
-    type_object = float
+    type_object = FloatType
+    type_converter = float
     type_error = "must be a number"
 
 
@@ -568,7 +569,8 @@
     """
 
     widget_type = "int"
-    type_object = int
+    type_object = IntType
+    type_converter = int
     type_error = "must be an integer"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.