Commit 38a00dd9 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use isinstance to check types.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5663 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3be71dd3
...@@ -192,7 +192,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -192,7 +192,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
property_sheet_definition_dict.items(): property_sheet_definition_dict.items():
if hasattr(base, ps_property_name): if hasattr(base, ps_property_name):
ps_property = getattr(base, ps_property_name) ps_property = getattr(base, ps_property_name)
if type(ps_property) in (type(()), type([])): if isinstance(ps_property, (tuple, list)):
current_list += ps_property current_list += ps_property
else : else :
raise ValueError, "%s is not a list for %s" % (ps_property_name, raise ValueError, "%s is not a list for %s" % (ps_property_name,
...@@ -590,7 +590,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -590,7 +590,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
from Globals import get_request from Globals import get_request
TRANSACTION = get_transaction() TRANSACTION = get_transaction()
if not hasattr(TRANSACTION, '_erp5_acquisition_stack'): TRANSACTION._erp5_acquisition_stack = {} if not hasattr(TRANSACTION, '_erp5_acquisition_stack'): TRANSACTION._erp5_acquisition_stack = {}
if type(portal_type) is type([]): if isinstance(portal_type, list):
portal_type = tuple(portal_type) portal_type = tuple(portal_type)
acquisition_key = ('_getDefaultAcquiredProperty', self.getPath(), key, base_category, acquisition_key = ('_getDefaultAcquiredProperty', self.getPath(), key, base_category,
portal_type, copy_value, mask_value, sync_value, portal_type, copy_value, mask_value, sync_value,
...@@ -640,7 +640,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -640,7 +640,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if value is None: if value is None:
result = None result = None
else: else:
if type(value) is type([]) or type(value) is type(()): if isinstance(value, (list, tuple)):
if len(value) is 0: if len(value) is 0:
result = None result = None
else: else:
...@@ -666,7 +666,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -666,7 +666,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
result = method() result = method()
if result is not None: if result is not None:
if is_list_type: if is_list_type:
if type(result) is type([]) or type(result) is type(()): if isinstance(result, (list, tuple)):
# We must provide the first element of the alternate result # We must provide the first element of the alternate result
if len(result) > 0: if len(result) > 0:
# Pop context # Pop context
...@@ -734,7 +734,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -734,7 +734,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if accessor_id is None: if accessor_id is None:
if is_list_type: if is_list_type:
result = super.getPropertyList(key) result = super.getPropertyList(key)
if type(result) is type([]) or type(result) is type(()): if isinstance(result, (list, tuple)):
value += result value += result
else: else:
value += [result] value += [result]
...@@ -744,7 +744,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -744,7 +744,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
method = getattr(super, accessor_id) method = getattr(super, accessor_id)
if is_list_type: if is_list_type:
result = method() # We should add depends here result = method() # We should add depends here
if type(result) is type([]) or type(result) is type(()): if isinstance(result, (list, tuple)):
value += result value += result
else: else:
value += [result] value += [result]
...@@ -881,7 +881,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -881,7 +881,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def _setPropValue(self, key, value, **kw): def _setPropValue(self, key, value, **kw):
#LOG('_setPropValue', 0, 'self = %r, key = %r, value = %r, kw = %r' % (self, key, value, kw)) #LOG('_setPropValue', 0, 'self = %r, key = %r, value = %r, kw = %r' % (self, key, value, kw))
self._wrapperCheck(value) self._wrapperCheck(value)
if type(value) == type([]): if isinstance(value, list):
value = tuple(value) value = tuple(value)
accessor_name = '_set' + UpperCase(key) accessor_name = '_set' + UpperCase(key)
aq_self = aq_base(self) aq_self = aq_base(self)
...@@ -1097,7 +1097,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1097,7 +1097,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
TODO: TODO:
- strict_membership is not implemented - strict_membership is not implemented
""" """
if type(base_category) is type('a'): if isinstance(base_category, str):
base_category = self.portal_categories[base_category] base_category = self.portal_categories[base_category]
if base_category is None: if base_category is None:
sql_text = '(%s.category_uid = %s)' % \ sql_text = '(%s.category_uid = %s)' % \
...@@ -1276,14 +1276,14 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1276,14 +1276,14 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def _setValue(self, id, target, spec=(), filter=None, portal_type=()): def _setValue(self, id, target, spec=(), filter=None, portal_type=()):
if target is None : if target is None :
path = target path = target
elif type(target) is type('a'): elif isinstance(target, str):
# We have been provided a string # We have been provided a string
path = target path = target
elif type(target) is type(('a','b')) or type(target) is type(['a','b']): elif isinstance(target, (tuple, list)):
# We have been provided a list or tuple # We have been provided a list or tuple
path_list = [] path_list = []
for target_item in target: for target_item in target:
if type(target_item) is type('a'): if isinstance(target_item, str):
path_list += [target_item] path_list += [target_item]
else: else:
path = target_item.getRelativeUrl() path = target_item.getRelativeUrl()
...@@ -2082,7 +2082,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -2082,7 +2082,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if hasattr(self,permission_name): if hasattr(self,permission_name):
delattr(self,permission_name) delattr(self,permission_name)
else: else:
if type(local_permission_list) is type('a'): if isinstance(local_permission_list, str):
local_permission_list = (local_permission_list,) local_permission_list = (local_permission_list,)
setattr(self,permission_name,tuple(local_permission_list)) setattr(self,permission_name,tuple(local_permission_list))
......
...@@ -63,9 +63,7 @@ class CopyContainer: ...@@ -63,9 +63,7 @@ class CopyContainer:
elif uids is None: elif uids is None:
raise ValueError, 'uids must be specified' raise ValueError, 'uids must be specified'
if type(uids) is type(''): if isinstance(uids, (str, int)):
ids=[uids]
if type(uids) is type(1):
ids=[uids] ids=[uids]
oblist=[] oblist=[]
for uid in uids: for uid in uids:
...@@ -130,9 +128,7 @@ class CopyContainer: ...@@ -130,9 +128,7 @@ class CopyContainer:
elif uids is None: elif uids is None:
raise ValueError, 'uids must be specified' raise ValueError, 'uids must be specified'
if type(uids) is type(''): if isinstance(uids, (str, int)):
ids=[uids]
if type(uids) is type(1):
ids=[uids] ids=[uids]
oblist=[] oblist=[]
for uid in uids: for uid in uids:
...@@ -162,8 +158,8 @@ class CopyContainer: ...@@ -162,8 +158,8 @@ class CopyContainer:
if len(ids) > 0: if len(ids) > 0:
# Use default method # Use default method
return ObjectManager.manage_delObjects(self, ids, REQUEST) return ObjectManager.manage_delObjects(self, ids, REQUEST)
if type(uids) is type(''): ids=[uids] if isinstance(uids, (str, int)):
if type(uids) is type(1): ids=[uids] ids=[uids]
if not uids: if not uids:
return MessageDialog(title='No items specified', return MessageDialog(title='No items specified',
message='No items were specified!', message='No items were specified!',
......
...@@ -54,7 +54,7 @@ class RoleInformation( SimpleItem ): ...@@ -54,7 +54,7 @@ class RoleInformation( SimpleItem ):
): ):
""" Set up an instance. """ Set up an instance.
""" """
if condition and type( condition ) == type( '' ): if condition and isinstance(condition, str):
condition = Expression( condition ) condition = Expression( condition )
self.id = id self.id = id
......
...@@ -70,12 +70,12 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw): ...@@ -70,12 +70,12 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
"""Sort values in a way compatible with ZSQLCatalog. """Sort values in a way compatible with ZSQLCatalog.
""" """
if sort_on is not None: if sort_on is not None:
if type(sort_on) == type(''): if isinstance(sort_on, str):
sort_on = (sort_on,) sort_on = (sort_on,)
reverse = (sort_order in ('descending', 'reverse', 'DESC')) reverse = (sort_order in ('descending', 'reverse', 'DESC'))
new_sort_on = [] new_sort_on = []
for key in sort_on: for key in sort_on:
if type(key) == type(''): if isinstance(key, str):
new_sort_on.append((key, reverse, None)) new_sort_on.append((key, reverse, None))
else: else:
if len(key) == 1: if len(key) == 1:
...@@ -207,9 +207,9 @@ def getPath(object_or_path,tuple=0): ...@@ -207,9 +207,9 @@ def getPath(object_or_path,tuple=0):
""" """
Returns the absolute path of an object Returns the absolute path of an object
""" """
if type(object_or_path) in (type([]), type(())): if isinstance(object_or_path, (list, tuple)):
path = '/'.join(object_or_path) path = '/'.join(object_or_path)
elif type(object_or_path) is type('a'): elif isinstance(object_or_path, str):
path = object_or_path path = object_or_path
else: else:
path = object_or_path.getPhysicalPath() path = object_or_path.getPhysicalPath()
...@@ -393,7 +393,7 @@ base_category_dict = {} ...@@ -393,7 +393,7 @@ base_category_dict = {}
def registerBaseCategories(property_sheet): def registerBaseCategories(property_sheet):
global base_category_dict global base_category_dict
category_list = getattr(property_sheet, '_categories', ()) category_list = getattr(property_sheet, '_categories', ())
if type(category_list) is type('') : if isinstance(category_list, str):
category_list = (category_list,) category_list = (category_list,)
for bc in category_list : for bc in category_list :
#LOG('registerBaseCategories', 0, 'bc = %r in %s' % (bc, property_sheet)) #LOG('registerBaseCategories', 0, 'bc = %r in %s' % (bc, property_sheet))
...@@ -692,7 +692,7 @@ def importLocalDocument(class_id, document_path = None): ...@@ -692,7 +692,7 @@ def importLocalDocument(class_id, document_path = None):
pr=PermissionRole(document_class.add_permission, default_permission) pr=PermissionRole(document_class.add_permission, default_permission)
m[initial.__name__+'__roles__']=pr m[initial.__name__+'__roles__']=pr
for method in constructors[1:]: for method in constructors[1:]:
if type(method) is type((1,2)): if isinstance(method, tuple):
name, method = method name, method = method
else: else:
name=os.path.split(method.__name__)[-1] name=os.path.split(method.__name__)[-1]
...@@ -1009,7 +1009,7 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1009,7 +1009,7 @@ def setDefaultProperties(property_holder, object=None):
# Copy the dict so that Expression objects are not overwritten. # Copy the dict so that Expression objects are not overwritten.
prop_list.append(prop.copy()) prop_list.append(prop.copy())
if hasattr(base, '_categories'): if hasattr(base, '_categories'):
if type(base._categories) in (type(()), type([])): if isinstance(base._categories, (tuple, list)):
cat_list += base._categories cat_list += base._categories
else: else:
cat_list += [base._categories] cat_list += [base._categories]
...@@ -1025,7 +1025,7 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1025,7 +1025,7 @@ def setDefaultProperties(property_holder, object=None):
for cat in cat_list: for cat in cat_list:
if isinstance(cat, Expression): if isinstance(cat, Expression):
result = cat(econtext) result = cat(econtext)
if type(result) in (type(()), type([])): if isinstance(result, (tuple, list)):
new_cat_list.extend(result) new_cat_list.extend(result)
else: else:
new_cat_list.append(result) new_cat_list.append(result)
...@@ -1117,7 +1117,7 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1117,7 +1117,7 @@ def setDefaultProperties(property_holder, object=None):
for cat in base_category_dict.keys(): for cat in base_category_dict.keys():
if isinstance(cat, Expression): if isinstance(cat, Expression):
result = cat(econtext) result = cat(econtext)
if type(result) in (type(()), type([])): if isinstance(result, (list, tuple)):
base_category_list.extend(result) base_category_list.extend(result)
else: else:
base_category_list.append(result) base_category_list.append(result)
...@@ -2601,7 +2601,7 @@ def assertAttributePortalType(o, attribute_name, portal_type): ...@@ -2601,7 +2601,7 @@ def assertAttributePortalType(o, attribute_name, portal_type):
# o._delObject(attribute_name) # o._delObject(attribute_name)
if hasattr(o,attribute_name): if hasattr(o,attribute_name):
try: try:
if type(portal_type) is type('a'): portal_type = [portal_type] if isinstance(portal_type, str): portal_type = [portal_type]
if getattr(o, attribute_name).portal_type not in portal_type: if getattr(o, attribute_name).portal_type not in portal_type:
o._delObject(attribute_name) o._delObject(attribute_name)
except (KeyError, AttributeError): except (KeyError, AttributeError):
......
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