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