quixote/form widget.py,1.29,1.30
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-serv18742
Modified Files:
widget.py
Log Message:
Remove import from types. Use builtin types instead.
Use %r in format strings.
Remove type_name and type_converter attributes from NumberWidget classes.
Index: widget.py
===================================================================
RCS file: /home/cvs/quixote/form/widget.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- widget.py 23 Oct 2002 20:25:04 -0000 1.29
+++ widget.py 28 Oct 2002 16:14:59 -0000 1.30
@@ -8,7 +8,6 @@
__revision__ = "$Id$"
-from types import *
from quixote import get_request
from quixote.html import htmltext, htmlescape, htmltag, ValuelessAttr
@@ -77,7 +76,7 @@
def parse (self, request):
"""parse(request) -> any"""
value = request.form.get(self.name)
- if type(value) is StringType and value.strip():
+ if type(value) is str and value.strip():
self.value = value
else:
self.value = None
@@ -257,9 +256,9 @@
def set_allowed_values (self, allowed_values, descriptions, sort=0):
- assert type(allowed_values) in (ListType, TupleType), (
- "allowed_values for '%s' not a list: got %s" % (self.name,
- `allowed_values`))
+ assert type(allowed_values) in (list, tuple), (
+ "allowed_values for '%s' not a list or tuple: got %r" %
+ (self.name, allowed_values))
self.allowed_values = allowed_values
if descriptions is None:
self.descriptions = []
@@ -270,9 +269,9 @@
v = str(v)
self.descriptions.append(v)
else:
- assert type(descriptions) in (ListType, TupleType), (
- "descriptions for '%s' not a list: got %s" % (self.name,
- `descriptions`))
+ assert type(descriptions) in (list, tuple), (
+ "descriptions for '%s' not a list or tuple: got %r" %
+ (self.name, descriptions))
assert len(self.allowed_values) == len(descriptions), (
"allowed_values and descriptions must be the same length: "
"not %s and %s" % (len(self.allowed_values),
@@ -339,7 +338,7 @@
value = request.form.get(self.name)
self.value = None
if value:
- if type(value) is ListType:
+ if type(value) is list:
raise FormValueError, "cannot select multiple values"
try:
index = int(value)
@@ -416,7 +415,7 @@
def set_value (self, value):
if value in self.allowed_values:
self.value = [value]
- elif type(value) in (ListType, TupleType):
+ elif type(value) in (list, tuple):
self.value = [val for val in value
if val in self.allowed_values] or None
else:
@@ -424,7 +423,7 @@
def is_selected (self, value):
- if type(self.value) in (ListType, TupleType) and value in self.value:
+ if type(self.value) in (list, tuple) and value in self.value:
return 1
return value == self.value
@@ -443,7 +442,7 @@
value = request.form.get(self.name)
self.value = []
if value:
- if type(value) is ListType:
+ if type(value) is list:
for val in value:
self.append_value(val)
else:
@@ -520,9 +519,7 @@
# Parameterize the number type (either float or int) through
# these class attributes:
- type_object = None # eg. IntType, FloatType
- type_name = None # eg. "int", "float"
- type_converter = None # eg int(), float() (builtin function)
+ type_object = None # eg. int, float
type_error = None # human-readable error message
def __init__ (self, name,
@@ -530,9 +527,9 @@
size=None, maxlength=None):
assert self.__class__ is not NumberWidget, "abstract class"
assert value is None or type(value) is self.type_object, (
- "form value '%s' not a %s: got %s" % (name,
+ "form value '%s' not a %s: got %r" % (name,
self.type_object,
- `value`))
+ value))
StringWidget.__init__(self, name, value, size, maxlength)
@@ -547,7 +544,7 @@
value = StringWidget.parse(self, request)
if value:
try:
- self.value = self.type_converter(value)
+ self.value = self.type_object(value)
except ValueError:
raise FormValueError, self.type_error
return self.value
@@ -560,9 +557,7 @@
"""
widget_type = "float"
- type_object = FloatType
- type_name = "float"
- type_converter = float
+ type_object = float
type_error = "must be a number"
@@ -573,9 +568,7 @@
"""
widget_type = "int"
- type_object = IntType
- type_name = "int"
- type_converter = int
+ type_object = int
type_error = "must be an integer"
@@ -632,11 +625,11 @@
element_type=None,
element_name="row",
**args):
- assert value is None or type(value) is ListType, (
- "form value '%s' not a ListType: got %s" % (name, `value`))
- assert type(element_name) in (StringType, htmltext), (
+ assert value is None or type(value) is list, (
+ "form value '%s' not a list: got %r" % (name, value))
+ assert type(element_name) in (str, htmltext), (
"form value '%s' element_name not a string: "
- "got %s" % (name, `element_name`))
+ "got %r" % (name, element_name))
Widget.__init__(self, name, value)