Commit b0b7d1b6 authored by Jérome Perrin's avatar Jérome Perrin

use isinstance to check types.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16786 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fad91b56
...@@ -140,7 +140,7 @@ def SelectionValidator_validate(self, field, key, REQUEST): ...@@ -140,7 +140,7 @@ def SelectionValidator_validate(self, field, key, REQUEST):
# will remain integers. # will remain integers.
# XXX it is impossible with the UI currently to fill in unicode # XXX it is impossible with the UI currently to fill in unicode
# items, but it's possible to do it with the TALES tab # items, but it's possible to do it with the TALES tab
if field.get_value('unicode') and type(item_value) == type(u''): if field.get_value('unicode') and isinstance(item_value, unicode):
str_value = item_value.encode(field.get_form_encoding()) str_value = item_value.encode(field.get_form_encoding())
else: else:
str_value = str(item_value) str_value = str(item_value)
...@@ -186,7 +186,7 @@ def SelectionValidator_validate(self, field, key, REQUEST): ...@@ -186,7 +186,7 @@ def SelectionValidator_validate(self, field, key, REQUEST):
# will remain integers. # will remain integers.
# XXX it is impossible with the UI currently to fill in unicode # XXX it is impossible with the UI currently to fill in unicode
# items, but it's possible to do it with the TALES tab # items, but it's possible to do it with the TALES tab
if field.get_value('unicode') and type(item_value) == type(u''): if field.get_value('unicode') and isinstance(item_value, unicode):
str_value = item_value.encode(field.get_form_encoding()) str_value = item_value.encode(field.get_form_encoding())
else: else:
str_value = str(item_value) str_value = str(item_value)
...@@ -207,7 +207,7 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST): ...@@ -207,7 +207,7 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST):
raise KeyError, 'Field %s is not present in request object (marker field default_%s not found).' % (repr(field.id), key) raise KeyError, 'Field %s is not present in request object (marker field default_%s not found).' % (repr(field.id), key)
values = REQUEST.get(key, []) values = REQUEST.get(key, [])
# NOTE: a hack to deal with single item selections # NOTE: a hack to deal with single item selections
if type(values) is not type([]): if not isintance(values, list):
# put whatever we got in a list # put whatever we got in a list
values = [values] values = [values]
# if we selected nothing and entry is required, give error, otherwise # if we selected nothing and entry is required, give error, otherwise
...@@ -232,7 +232,7 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST): ...@@ -232,7 +232,7 @@ def MultiSelectionValidator_validate(self, field, key, REQUEST):
item_value = item item_value = item
value_dict[item_value] = 0 value_dict[item_value] = 0
default_value = field.get_value('default', cell=getattr(REQUEST,'cell',None)) default_value = field.get_value('default', cell=getattr(REQUEST,'cell',None))
if type(default_value) in (type([]), type(())): if isinstance(default_value, (list, tuple)):
for v in default_value: for v in default_value:
value_dict[v] = 0 value_dict[v] = 0
else: else:
...@@ -359,7 +359,7 @@ class IntegerWidget(TextWidget) : ...@@ -359,7 +359,7 @@ class IntegerWidget(TextWidget) :
def render(self, field, key, value, REQUEST) : def render(self, field, key, value, REQUEST) :
"""Render an editable integer. """Render an editable integer.
""" """
if type(value) is type(1.0): if isinstance(value, float):
value = int(value) value = int(value)
display_maxwidth = field.get_value('display_maxwidth') or 0 display_maxwidth = field.get_value('display_maxwidth') or 0
if display_maxwidth > 0: if display_maxwidth > 0:
...@@ -425,7 +425,7 @@ def StringBaseValidator_validate(self, field, key, REQUEST): ...@@ -425,7 +425,7 @@ def StringBaseValidator_validate(self, field, key, REQUEST):
raise Exception, 'Required field %s has not been transmitted. Check that all required fields are in visible groups.' % (repr(field.id), ) raise Exception, 'Required field %s has not been transmitted. Check that all required fields are in visible groups.' % (repr(field.id), )
else: else:
raise KeyError, 'Field %s is not present in request object.' % (repr(field.id), ) raise KeyError, 'Field %s is not present in request object.' % (repr(field.id), )
if type(value) is type('a'): if isinstance(value, str):
value = string.strip(value) value = string.strip(value)
if field.get_value('required') and value == "": if field.get_value('required') and value == "":
self.raise_error('required_not_found', field) self.raise_error('required_not_found', field)
...@@ -447,7 +447,7 @@ def Widget_render_hidden(self, field, key, value, REQUEST): ...@@ -447,7 +447,7 @@ def Widget_render_hidden(self, field, key, value, REQUEST):
result = '' result = ''
# We must adapt the rendering to the type of the value # We must adapt the rendering to the type of the value
# in order to get the correct type back # in order to get the correct type back
if type(value) is type([]) or type(value) is type(()): if isinstance(value, (tuple, list)):
for v in value: for v in value:
result += render_element("input", result += render_element("input",
type="hidden", type="hidden",
...@@ -485,7 +485,7 @@ from Products.Formulator.Validator import LinesValidator ...@@ -485,7 +485,7 @@ from Products.Formulator.Validator import LinesValidator
def LinesValidator_validate(self, field, key, REQUEST): def LinesValidator_validate(self, field, key, REQUEST):
value = StringBaseValidator.validate(self, field, key, REQUEST) value = StringBaseValidator.validate(self, field, key, REQUEST)
# Added as a patch for hidden values # Added as a patch for hidden values
if type(value) is type([]) or type(value) is type(()): if isinstance(value, (list, tuple)):
value = string.join(value, "\n") value = string.join(value, "\n")
# we need to add this check again # we need to add this check again
if value == "" and not field.get_value('required'): if value == "" and not field.get_value('required'):
...@@ -603,10 +603,10 @@ from Products.Formulator.Widget import MultiItemsWidget ...@@ -603,10 +603,10 @@ from Products.Formulator.Widget import MultiItemsWidget
def MultiItemsWidget_render_items(self, field, key, value, REQUEST): def MultiItemsWidget_render_items(self, field, key, value, REQUEST):
# list is needed, not a tuple # list is needed, not a tuple
if type(value) is type(()): if isinstance(value, tuple):
value = list(value) value = list(value)
# need to deal with single item selects # need to deal with single item selects
if type(value) is not type([]): if not isinstance(value, list):
value = [value] value = [value]
# XXX -yo # XXX -yo
...@@ -805,7 +805,7 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -805,7 +805,7 @@ class PatchedDateTimeWidget(DateTimeWidget):
format_dict = self.format_to_sql_format_dict format_dict = self.format_to_sql_format_dict
input_order = format_dict.get(self.getInputOrder(field), input_order = format_dict.get(self.getInputOrder(field),
self.sql_format_default) self.sql_format_default)
if type(value) == type(u''): if isinstance(value, unicode):
value = value.encode(field.get_form_encoding()) value = value.encode(field.get_form_encoding())
return {'query': value, return {'query': value,
'format': field.get_value('date_separator').join(input_order), 'format': field.get_value('date_separator').join(input_order),
...@@ -832,7 +832,7 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -832,7 +832,7 @@ class PatchedDateTimeWidget(DateTimeWidget):
hour = None hour = None
minute = None minute = None
ampm = None ampm = None
if type(value) is type(DateTime()): if isinstance(value, DateTime):
year = "%04d" % value.year() year = "%04d" % value.year()
month = "%02d" % value.month() month = "%02d" % value.month()
day = "%02d" % value.day() day = "%02d" % value.day()
...@@ -1176,7 +1176,7 @@ class FloatWidget(TextWidget): ...@@ -1176,7 +1176,7 @@ class FloatWidget(TextWidget):
input_style += '5' input_style += '5'
else: else:
input_style = input_style.split('.')[0] input_style = input_style.split('.')[0]
if type(value) == type(u''): if isinstance(value, unicode):
value = value.encode(field.get_form_encoding()) value = value.encode(field.get_form_encoding())
return {'query': value, return {'query': value,
'format': input_style, 'format': input_style,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment