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

use isinstance to check types, do not override type builtin.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8924 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e59a3ba6
...@@ -40,12 +40,11 @@ def PropertyManager_updateProperty(self, id, value): ...@@ -40,12 +40,11 @@ def PropertyManager_updateProperty(self, id, value):
self._wrapperCheck(value) self._wrapperCheck(value)
if not hasattr(self, 'isRADContent'): if not hasattr(self, 'isRADContent'):
if not self.hasProperty(id): if not self.hasProperty(id):
raise 'Bad Request', 'The property %s does not exist' % escape(id) raise BadRequest, 'The property %s does not exist' % escape(id)
if type(value)==type(''): if isinstance(value, str):
proptype=self.getPropertyType(id) or 'string' proptype=self.getPropertyType(id) or 'string'
if type_converters.has_key(proptype): if type_converters.has_key(proptype):
value=type_converters[proptype](value) value=type_converters[proptype](value)
#LOG('_updateProperty', 0, 'self = %r, id = %r, value = %r' % (self, id, value))
self._setPropValue(id, value) self._setPropValue(id, value)
def PropertyManager_hasProperty(self, id): def PropertyManager_hasProperty(self, id):
...@@ -58,13 +57,13 @@ def PropertyManager_hasProperty(self, id): ...@@ -58,13 +57,13 @@ def PropertyManager_hasProperty(self, id):
def PropertyManager_getProperty(self, id, d=None, evaluate=1): def PropertyManager_getProperty(self, id, d=None, evaluate=1):
"""Get the property 'id', returning the optional second """Get the property 'id', returning the optional second
argument or None if no such property is found.""" argument or None if no such property is found."""
type = self.getPropertyType(id) property_type = self.getPropertyType(id)
if evaluate and type == 'tales': if evaluate and property_type == 'tales':
value = getattr(self, id) value = getattr(self, id)
expression = Expression(value) expression = Expression(value)
econtext = createExpressionContext(self) econtext = createExpressionContext(self)
return expression(econtext) return expression(econtext)
elif type: elif property_type:
return getattr(self, id) return getattr(self, id)
return d return d
...@@ -83,16 +82,15 @@ def PropertyManager_setProperty(self, id, value, type=None): ...@@ -83,16 +82,15 @@ def PropertyManager_setProperty(self, id, value, type=None):
if type is None: if type is None:
# Generate a default type # Generate a default type
value_type = type(value) if isinstance(value, (list, tuple)):
if value_type in (type([]), type(())):
type = 'lines' type = 'lines'
elif value_type is type(1): elif isinstance(value, int):
type = 'int' type = 'int'
elif value_type is type(1L): elif isinstance(value, long):
type = 'long' type = 'long'
elif value_type is type(1.0): elif isinstance(value, float):
type = 'float' type = 'float'
elif value_type is type('a'): elif isinstance(value, basestring):
if len(value_type.split('\n')) > 1: if len(value_type.split('\n')) > 1:
type = 'text' type = 'text'
else: else:
...@@ -114,7 +112,8 @@ def PropertyManager_setProperty(self, id, value, type=None): ...@@ -114,7 +112,8 @@ def PropertyManager_setProperty(self, id, value, type=None):
else: else:
self._setPropValue(id, []) self._setPropValue(id, [])
else: else:
self._local_properties=getattr(self, '_local_properties', ())+({'id':id,'type':type},) self._local_properties = getattr(self,
'_local_properties', ()) + ({'id':id, 'type':type},)
self._setPropValue(id, value) self._setPropValue(id, value)
def PropertyManager_delProperty(self, id): def PropertyManager_delProperty(self, id):
......
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